29 lines
720 B
Go
29 lines
720 B
Go
package globalcare
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"fmt"
|
|
)
|
|
|
|
// GeneratePublicKeyFromBytes ...
|
|
func generatePublicKeyFromBytes(b []byte) (*rsa.PublicKey, error) {
|
|
pubPem, _ := pem.Decode(b)
|
|
p, err := x509.ParsePKIXPublicKey(pubPem.Bytes)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("prsa.GeneratePublicKeyFromBytes: ParsePKIXPublicKey %v", err)
|
|
}
|
|
return p.(*rsa.PublicKey), nil
|
|
}
|
|
|
|
// GeneratePrivateKeyFromBytes ...
|
|
func generatePrivateKeyFromBytes(b []byte) (*rsa.PrivateKey, error) {
|
|
privPem, _ := pem.Decode(b)
|
|
p, err := x509.ParsePKCS1PrivateKey(privPem.Bytes)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("prsa.GeneratePrivateKeyFromBytes: ParsePKCS1PrivateKey %v", err)
|
|
}
|
|
return p, nil
|
|
}
|