Merge pull request #15 from writeas/fix-key-decoding

Support decoding PKCS#8 keys
This commit is contained in:
Matt Baer
2022-11-11 01:58:35 -05:00
committed by GitHub
+2 -2
View File
@@ -69,8 +69,8 @@ func parsePublicKey(der []byte) (crypto.PublicKey, error) {
// them in that order. // them in that order.
func DecodePrivateKey(k []byte) (crypto.PrivateKey, error) { func DecodePrivateKey(k []byte) (crypto.PrivateKey, error) {
block, _ := pem.Decode(k) block, _ := pem.Decode(k)
if block == nil || block.Type != "RSA PRIVATE KEY" { if block == nil || (block.Type != "RSA PRIVATE KEY" && block.Type != "PRIVATE KEY") {
return nil, fmt.Errorf("failed to decode PEM block containing private key") return nil, fmt.Errorf("failed to decode PEM block containing private key, type %s", block.Type)
} }
return parsePrivateKey(block.Bytes) return parsePrivateKey(block.Bytes)