Created
November 29, 2020 19:42
-
-
Save jedisct1/d6cb41742a1ceb54d48cc286f3d5c5fa to your computer and use it in GitHub Desktop.
Compute the hash of a TLS certificate
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/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