Last active
September 27, 2016 16:39
-
-
Save vbatts/ea6df817924e7ade5d60bba163d51867 to your computer and use it in GitHub Desktop.
get the digest of the public key per rfc5280 https://tools.ietf.org/html/rfc5280#section-4.2.1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/rsa" | |
"crypto/sha1" | |
"crypto/tls" | |
"encoding/asn1" | |
"fmt" | |
"log" | |
"os" | |
) | |
// Usage: go run keyid.go ./my.crt ./my.key | |
// > f1f6a4a0cd859c01a5458d8bc39190a6435793bd | |
func main() { | |
cert, err := tls.LoadX509KeyPair(os.Args[1], os.Args[2]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
key, ok := cert.PrivateKey.(*rsa.PrivateKey) | |
if !ok { | |
log.Fatal("does not look like an RSA key") | |
} | |
mdata, err := asn1.Marshal(key.PublicKey) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%x\n", sha1.Sum(mdata)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment