This commit is contained in:
parent
fe3e02b80a
commit
3a4d44cae7
2 changed files with 71 additions and 4 deletions
|
@ -4,14 +4,19 @@ import (
|
|||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error) {
|
||||
block, _ := pem.Decode(priv)
|
||||
b := block.Bytes
|
||||
key, err := x509.ParsePKCS1PrivateKey(b)
|
||||
func BytesToPrivateKey(b []byte) (*rsa.PrivateKey, error) {
|
||||
block, _ := pem.Decode(b)
|
||||
if block == nil {
|
||||
return nil, errors.New("PEM decode failed")
|
||||
}
|
||||
|
||||
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return key, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue