func Fingerprint(pemData []byte) (string, []byte, error) {
	block, rest := pem.Decode(pemData)
	if block == nil {
		return "", rest, errors.New(
			"input does not contain a valid certificate in PEM format")
	} else if block.Type != PEMTypeCertificate {
		return "", rest, errors.NotValidf(
			"discovered pem block is not of type %s", PEMTypeCertificate)
	}

	if _, err := x509.ParseCertificate(block.Bytes); err != nil {
		return "", rest, errors.Annotate(err, "cannot parse pem certificate to x509")
	}

	// fingerprint format is: XX:YY:...:ZZ
	fingerprint := make([]byte, (sha256.Size*3)-1)
	var index int
	for _, fb := range sha256.Sum256(block.Bytes) {
		if index != 0 {
			fingerprint[index] = ':'
			index++
		}

		// Encode each byte as two chars
		fingerprint[index] = hexAlphabet[(fb>>4)&0xf]
		fingerprint[index+1] = hexAlphabet[fb&0xf]
		index += 2
	}

	return string(fingerprint), rest, nil
}
// Fingerprint returns a human-readable SHA-256 fingerprint for a certificate
// stored in the PEM format. The returned fingerprint matches the output of:
// openssl x509 -noout -fingerprint -sha256 -inform pem -in cert.pem. Also
// returns the remainder of the input for the next blocks.
Fingerprint returns a human-readable SHA-256 fingerprint for a certificate
stored in the PEM format. The returned fingerprint matches the output of:
openssl x509 -noout -fingerprint -sha256 -inform pem -in cert.pem. Also
returns the remainder of the input for the next blocks.
// Fingerprint returns a human - readable SHA - 256 fingerprint for a certificate // stored in the PEM format . The returned fingerprint matches the output of : // openssl x509 - noout - fingerprint - sha256 - inform pem - in cert . pem . Also // returns the remainder of the input for the next blocks .
func Fingerprint(pemData []byte) (string, []byte, error) {
	block, rest := pem.Decode(pemData)
	if block == nil {
		return "", rest, errors.New(
			"input does not contain a valid certificate in PEM format")
	} else if block.Type != PEMTypeCertificate {
		return "", rest, errors.NotValidf(
			"discovered pem block is not of type %s", PEMTypeCertificate)
	}
	if _, err := x509.ParseCertificate(block.Bytes); err != nil {
		return "", rest, errors.Annotate(err, "cannot parse pem certificate to x509")
	}
	fingerprint := make([]byte, (sha256.Size*3)-1)
	var index int
	for _, fb := range sha256.Sum256(block.Bytes) {
		if index != 0 {
			fingerprint[index] = ':'
			index++
		}
		fingerprint[index] = hexAlphabet[(fb>>4)&0xf]
		fingerprint[index+1] = hexAlphabet[fb&0xf]
		index += 2
	}
	return string(fingerprint), rest, nil
}
func Fingerprint ( pemData [ ] byte ) ( string , [ ] byte , error ) { block , rest := pem . Decode ( pemData ) if block == nil { return " " , rest , errors . New ( " " ) } else if block . Type != PEMTypeCertificate { return " " , rest , errors . NotValidf ( " " , PEMTypeCertificate ) } if _ , err := x509 . ParseCertificate ( block . Bytes ) ; err != nil { return " " , rest , errors . Annotate ( err , " " ) } fingerprint := make ( [ ] byte , ( sha256 . Size * 3 ) - 1 ) var index int for _ , fb := range sha256 . Sum256 ( block . Bytes ) { if index != 0 { fingerprint [ index ] = ':' index ++ } fingerprint [ index ] = hexAlphabet [ ( fb >> 4 ) & 0xf ] fingerprint [ index + 1 ] = hexAlphabet [ fb & 0xf ] index += 2 } return string ( fingerprint ) , rest , nil }
Fingerprint returns a human-readable SHA-256 fingerprint for a certificate
stored in the PEM format.
Fingerprint returns a human - readable SHA - 256 fingerprint for a certificate stored in the PEM format .
// fingerprint format is: XX:YY:...:ZZ // Encode each byte as two chars