-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsa.go
44 lines (38 loc) · 884 Bytes
/
rsa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package corjwt
import (
"crypto/rsa"
"io/ioutil"
"github.com/dgrijalva/jwt-go"
)
// PrivateRSAFromPemFile ...
func PrivateRSAFromPemFile(fileName string) (*rsa.PrivateKey, error) {
contents, err := ioutil.ReadFile(fileName)
if err != nil {
return nil, err
}
return PrivateRSA(contents)
}
// PrivateRSA ...
func PrivateRSA(contents []byte) (*rsa.PrivateKey, error) {
key, err := jwt.ParseRSAPrivateKeyFromPEM(contents)
if err != nil {
return nil, err
}
return key, err
}
// PublicRSAFromPemFile ...
func PublicRSAFromPemFile(fileName string) (*rsa.PublicKey, error) {
contents, err := ioutil.ReadFile(fileName)
if err != nil {
return nil, err
}
return PublicRSA(contents)
}
// PublicRSA ...
func PublicRSA(contents []byte) (*rsa.PublicKey, error) {
key, err := jwt.ParseRSAPublicKeyFromPEM(contents)
if err != nil {
return nil, err
}
return key, err
}