PKCS8 private key marshal?

Is there any way to marshal PKCS8 private key in go 1.5?
for example, something similar or starting with x509.MarshalPKCS1PrivateKey ?

+5
source share
1 answer

Funny, there is no standard function for this, but here is a custom solution:

 type pkcs8Key struct { Version int PrivateKeyAlgorithm []asn1.ObjectIdentifier PrivateKey []byte } func rsa2pkcs8(key *rsa.PrivateKey) ([]byte, error) { var pkey pkcs8Key pkey.Version = 0 pkey.PrivateKeyAlgorithm = make([]asn1.ObjectIdentifier, 1) pkey.PrivateKeyAlgorithm[0] = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1} pkey.PrivateKey = x509.MarshalPKCS1PrivateKey(key) return asn1.Marshal(pkey) } 
+4
source

Source: https://habr.com/ru/post/1236876/


All Articles