| 1 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ |
| 2 | |
| 3 | import ( |
| 4 | "cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/" |
| 5 | "crypto/ecdsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/ecdsa`/" |
| 6 | "crypto/ed25519scip-go gomod github.com/golang/go/src go1.25.0 `crypto/ed25519`/" |
| 7 | "crypto/rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/" |
| 8 | "math/bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/" |
| 9 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 10 | ) |
| 11 | |
| 12 | const formatscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/format. = "Private-key-format: v1.3\n" |
| 13 | |
| 14 | var bigIntOnescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/bigIntOne. = bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/NewInt().(1) |
| 15 | |
| 16 | // PrivateKeyString converts a PrivateKey to a string. This string has the same |
| 17 | // format as the private-key-file of BIND9 (Private-key-format: v1.3). |
| 18 | // It needs some info from the key (the algorithm), so its a method of the DNSKEY. |
| 19 | // It supports *rsa.PrivateKey, *ecdsa.PrivateKey and ed25519.PrivateKey. |
| 20 | func (r *DNSKEYscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DNSKEY#) PrivateKeyStringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DNSKEY#PrivateKeyString().(p cryptoscip-go gomod github.com/golang/go/src go1.25.0 crypto/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 crypto/PrivateKey#) string { |
| 21 | algorithm := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.0 strconv/Itoa().(int(r.Algorithmscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DNSKEY#Algorithm.)) |
| 22 | algorithm += " (" + AlgorithmToStringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/AlgorithmToString.[r.Algorithmscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DNSKEY#Algorithm.] + ")" |
| 23 | |
| 24 | switch p := p.(type) { |
| 25 | case *rsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#: |
| 26 | modulus := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(p.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#PublicKey..Nscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PublicKey#N..Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 27 | e := bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/NewInt().(int64(p.PublicKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#PublicKey..Escip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PublicKey#E.)) |
| 28 | publicExponent := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(e.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 29 | privateExponent := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(p.Dscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#D..Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 30 | prime1 := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[0].Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 31 | prime2 := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[1].Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 32 | // Calculate Exponent1/2 and Coefficient as per: http://en.wikipedia.org/wiki/RSA#Using_the_Chinese_remainder_algorithm |
| 33 | // and from: http://code.google.com/p/go/issues/detail?id=987 |
| 34 | p1 := new(bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#).Subscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Sub().(p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[0], bigIntOnescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/bigIntOne.) |
| 35 | q1 := new(bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#).Subscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Sub().(p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[1], bigIntOnescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/bigIntOne.) |
| 36 | exp1 := new(bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#).Modscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Mod().(p.Dscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#D., p1) |
| 37 | exp2 := new(bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#).Modscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Mod().(p.Dscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#D., q1) |
| 38 | coeff := new(bigscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#).ModInversescip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#ModInverse().(p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[1], p.Primesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/rsa`/PrivateKey#Primes.[0]) |
| 39 | |
| 40 | exponent1 := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(exp1.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 41 | exponent2 := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(exp2.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 42 | coefficient := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(coeff.Bytesscip-go gomod github.com/golang/go/src go1.25.0 `math/big`/Int#Bytes().()) |
| 43 | |
| 44 | return formatscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/format. + |
| 45 | "Algorithm: " + algorithm + "\n" + |
| 46 | "Modulus: " + modulus + "\n" + |
| 47 | "PublicExponent: " + publicExponent + "\n" + |
| 48 | "PrivateExponent: " + privateExponent + "\n" + |
| 49 | "Prime1: " + prime1 + "\n" + |
| 50 | "Prime2: " + prime2 + "\n" + |
| 51 | "Exponent1: " + exponent1 + "\n" + |
| 52 | "Exponent2: " + exponent2 + "\n" + |
| 53 | "Coefficient: " + coefficient + "\n" |
| 54 | |
| 55 | case *ecdsascip-go gomod github.com/golang/go/src go1.25.0 `crypto/ecdsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/ecdsa`/PrivateKey#: |
| 56 | var intlen int |
| 57 | switch r.Algorithmscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DNSKEY#Algorithm. { |
| 58 | case ECDSAP256SHA256scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ECDSAP256SHA256.: |
| 59 | intlen = 32 |
| 60 | case ECDSAP384SHA384scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ECDSAP384SHA384.: |
| 61 | intlen = 48 |
| 62 | } |
| 63 | private := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(intToBytesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/intToBytes().(p.Dscip-go gomod github.com/golang/go/src go1.25.0 `crypto/ecdsa`/PrivateKey#D., intlen)) |
| 64 | return formatscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/format. + |
| 65 | "Algorithm: " + algorithm + "\n" + |
| 66 | "PrivateKey: " + private + "\n" |
| 67 | |
| 68 | case ed25519scip-go gomod github.com/golang/go/src go1.25.0 `crypto/ed25519`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.25.0 `crypto/ed25519`/PrivateKey#: |
| 69 | private := toBase64scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/toBase64().(p.Seedscip-go gomod github.com/golang/go/src go1.25.0 `crypto/ed25519`/PrivateKey#Seed().()) |
| 70 | return formatscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/format. + |
| 71 | "Algorithm: " + algorithm + "\n" + |
| 72 | "PrivateKey: " + private + "\n" |
| 73 | |
| 74 | default: |
| 75 | return "" |
| 76 | } |
| 77 | } |