2015-11-26 15 views

Trả lời

4

vui đủ, không có chức năng tiêu chuẩn để làm điều đó, nhưng đây là một giải pháp tùy chỉnh:

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) 
} 
Các vấn đề liên quan