1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-05-06 17:29:35 +08:00
parent 25af24d7c0
commit cd0740f443
12 changed files with 102 additions and 6 deletions

View File

@ -54,6 +54,24 @@ func NewRsa(h Hash, opts ...rsaOption) (*rsaInstance, error) {
return o, nil
}
func ParsePKCS8PrivateKey(p []byte) rsaOption {
return func(o *rsaInstance) error {
block, _ := pem.Decode(p)
if block == nil {
return errors.New("failed to decode private key")
}
prk, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return err
}
o.prk = prk.(*rsa.PrivateKey)
return nil
}
}
func ParsePKCS1PrivateKey(p []byte) rsaOption {
return func(o *rsaInstance) error {
block, _ := pem.Decode(p)