Golang crypto/x509.ParsePKCS8PrivateKey() function example

package crypto/x509

ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private key. See http://www.rsa.com/rsalabs/node.asp?id=2130 and RFC5208.

Golang crypto/x509.ParsePKCS8PrivateKey() function usage example

 parsedKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
 if err != nil {
 parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
 if err != nil {
 return err
 }
 }

**NOTE : ParsePKCS8 is normally used to deal with unencrypted block first and if fail, then fall back to ParsePKCS1

Reference :

http://golang.org/pkg/crypto/x509/#ParsePKCS8PrivateKey

https://www.socketloop.com/references/golang-crypto-x509-parsepkcs1privatekey-function-example

Advertisement