Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compute the hash of a TLS certificate
package main
import (
func main() {
dat, err := ioutil.ReadFile("/tmp/cert.der")
if err != nil {
certs, err := x509.ParseCertificates(dat)
if err != nil {
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