Skip to content

Commit

Permalink
Merge pull request #77 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
feat(security): 兼容x509.ParsePKCS1PublicKey
  • Loading branch information
Matrix-X authored Apr 3, 2023
2 parents 1a09c0e + 09383d8 commit 1dd9932
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions security/encryption/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func (encryptor *RSAEncryptor) ParseRSAPublicKeyFromPEM(key []byte) (*rsa.Public
// Parse the key
var parsedKey interface{}
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {

// 兼容 x509.ParsePKCS1PublicKey的key
parsedKey, err = x509.ParsePKCS1PublicKey(block.Bytes)
if err == nil && parsedKey != nil {
return parsedKey.(*rsa.PublicKey), nil
}

// 尝试其他的证书格式 x509.ParseCertificate
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
parsedKey = cert.PublicKey
} else {
Expand Down

0 comments on commit 1dd9932

Please sign in to comment.