Source File
dnssec_privkey.go
Belonging Package
github.com/miekg/dns
package dnsimport ()const format = "Private-key-format: v1.3\n"var bigIntOne = big.NewInt(1)// PrivateKeyString converts a PrivateKey to a string. This string has the same// format as the private-key-file of BIND9 (Private-key-format: v1.3).// It needs some info from the key (the algorithm), so its a method of the DNSKEY.// It supports *rsa.PrivateKey, *ecdsa.PrivateKey and ed25519.PrivateKey.func ( *DNSKEY) ( crypto.PrivateKey) string {:= strconv.Itoa(int(.Algorithm))+= " (" + AlgorithmToString[.Algorithm] + ")"switch p := .(type) {case *rsa.PrivateKey::= toBase64(.PublicKey.N.Bytes()):= big.NewInt(int64(.PublicKey.E)):= toBase64(.Bytes()):= toBase64(.D.Bytes()):= toBase64(.Primes[0].Bytes()):= toBase64(.Primes[1].Bytes())// Calculate Exponent1/2 and Coefficient as per: http://en.wikipedia.org/wiki/RSA#Using_the_Chinese_remainder_algorithm// and from: http://code.google.com/p/go/issues/detail?id=987:= new(big.Int).Sub(.Primes[0], bigIntOne):= new(big.Int).Sub(.Primes[1], bigIntOne):= new(big.Int).Mod(.D, ):= new(big.Int).Mod(.D, ):= new(big.Int).ModInverse(.Primes[1], .Primes[0]):= toBase64(.Bytes()):= toBase64(.Bytes()):= toBase64(.Bytes())return format +"Algorithm: " + + "\n" +"Modulus: " + + "\n" +"PublicExponent: " + + "\n" +"PrivateExponent: " + + "\n" +"Prime1: " + + "\n" +"Prime2: " + + "\n" +"Exponent1: " + + "\n" +"Exponent2: " + + "\n" +"Coefficient: " + + "\n"case *ecdsa.PrivateKey:var intswitch .Algorithm {case ECDSAP256SHA256:= 32case ECDSAP384SHA384:= 48}:= toBase64(intToBytes(.D, ))return format +"Algorithm: " + + "\n" +"PrivateKey: " + + "\n"case ed25519.PrivateKey::= toBase64(.Seed())return format +"Algorithm: " + + "\n" +"PrivateKey: " + + "\n"default:return ""}}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |