Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go standard crypto package only support unencrypted PKCS#8 private keys #125

Open
Mycaster opened this issue Dec 12, 2018 · 0 comments
Open

Comments

@Mycaster
Copy link

Mycaster commented Dec 12, 2018

Go standard crypto package only support unencrypted PKCS#8 private keys
so this function cannot parse encrypted PKCS#8 private keys .

func parsePrivateKey(bytes []byte, password string) (crypto.PrivateKey, error) {
	var key crypto.PrivateKey
	key, err := x509.ParsePKCS1PrivateKey(bytes)
	if err == nil {
		return key, nil
	}
        //x509.ParsePKCS8PrivateKey not support parse encrypted PKCS#8 private keys
	key, err = x509.ParsePKCS8PrivateKey(bytes, []byte(password))  
	if err == nil {
		return key, nil
	}
	return nil, ErrFailedToParsePrivateKey
}

I tried another resposity https://github.com/youmark/pkcs8 , it works. maybe you can merge into your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant