Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created November 29, 2020 19:42
Show Gist options
  • Save jedisct1/d6cb41742a1ceb54d48cc286f3d5c5fa to your computer and use it in GitHub Desktop.
Save jedisct1/d6cb41742a1ceb54d48cc286f3d5c5fa to your computer and use it in GitHub Desktop.
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