mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
iter
This commit is contained in:
@ -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)
|
||||
|
@ -3,7 +3,6 @@ package crypto
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
s "github.com/tjfoc/gmsm/sm2"
|
||||
x "github.com/tjfoc/gmsm/x509"
|
||||
@ -54,8 +53,6 @@ func NewSm2(opts ...option) (*sm2Instance, error) {
|
||||
|
||||
func ParseSm2PrivateKey(p []byte, pwd []byte) option {
|
||||
return func(so *sm2Instance) error {
|
||||
fmt.Println(string(p))
|
||||
|
||||
priv, err := x.ReadPrivateKeyFromPem(p, pwd)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user