Skip to content

Instantly share code, notes, and snippets.

View solarfly73's full-sized avatar

Derek Douville solarfly73

  • Austin, TX
View GitHub Profile
@solarfly73
solarfly73 / from pkcs8
Created August 15, 2017 16:46
youmark pkcs8
func ConvertPrivateKeyToPKCS8(priv interface{}, v ...[]byte) ([]byte, error) {
if v == nil {
return convertPrivateKeyToPKCS8(priv)
}
password := string(v[0])
return convertPrivateKeyToPKCS8Encrypted(priv, []byte(password))
func ParsePKCS8PrivateKey(der []byte, v ...[]byte) (interface{}, error) {
// No password provided, assume the private key is unencrypted
if v == nil || len(v[0]) == 0 {
return x509.ParsePKCS8PrivateKey(der)
}
// Use the password provided to decrypt the private key
password := v[0]
var privKey encryptedPrivateKeyInfo