Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compute the hash of a TLS certificate
package main
import (
"crypto/sha256"
"crypto/x509"
"fmt"
"io/ioutil"
)
func main() {
dat, err := ioutil.ReadFile("/tmp/cert.der")
if err != nil {
panic(err)
}
certs, err := x509.ParseCertificates(dat)
if err != nil {
panic(err)
}
for _, cert := range certs {
h := sha256.Sum256(cert.RawTBSCertificate)
fmt.Printf("[%v]: %v\n", cert.Subject, fmt.Sprintf("%x", h))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment