Golang crypto/x509.Certificate.CheckSignature() function example

package crypto/x509

CheckSignature verifies that signature is a valid signature over signed from the given certificate's public key.

Golang crypto/x509.Certificate.CheckSignature() function usage

 var signature []byte
 err = cert.CheckSignature(x509.SHA256WithRSA, []byte(signingString), signature)
 if err != nil {
 fmt.Println("Key is not a valid RSA public key")
 os.Exit(1)
 }

or

 if err := x509.CheckSignature(cert.SignatureAlgorithm, cert.RawTBSCertificate, cert.Signature); err != nil {
 fmt.Println("Corrupted signature on embedded certificate")
 }

Reference :

http://golang.org/pkg/crypto/x509/#Certificate.CheckSignature

Advertisement