Skip to content

Commit 7e0750b

Browse files
authored
Create crypto.go
1 parent 9264a14 commit 7e0750b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

1.7/client/crypto.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package utils
2+
3+
import (
4+
"crypto/rsa"
5+
"crypto/x509"
6+
"encoding/pem"
7+
"fmt"
8+
"io/ioutil"
9+
)
10+
11+
func LoadPrivateKey(path string) (*rsa.PrivateKey, error) {
12+
keyData, err := ioutil.ReadFile(path)
13+
if err != nil {
14+
return nil, err
15+
}
16+
block, _ := pem.Decode(keyData)
17+
if block == nil || block.Type != "RSA PRIVATE KEY" {
18+
return nil, fmt.Errorf("invalid private key data")
19+
}
20+
return x509.ParsePKCS1PrivateKey(block.Bytes)
21+
}

0 commit comments

Comments
 (0)