-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.go
37 lines (30 loc) · 825 Bytes
/
token.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
package constant
import (
"crypto/rsa"
"io/ioutil"
jwt "github.com/dgrijalva/jwt-go"
)
//JWTPublicKey key
var JWTPublicKey *rsa.PublicKey
//JWTPrivateKey key
var JWTPrivateKey *rsa.PrivateKey
func init() {
JWTPrivateKey, _ = LoadRSAPrivateKeyFromDisk("keys/jwt")
JWTPublicKey, _ = LoadRSAPublicKeyFromDisk("keys/jwt.pub")
}
//LoadRSAPrivateKeyFromDisk load private key
func LoadRSAPrivateKeyFromDisk(location string) (*rsa.PrivateKey, error) {
keyData, e := ioutil.ReadFile(location)
if e != nil {
panic(e.Error())
}
return jwt.ParseRSAPrivateKeyFromPEM(keyData)
}
//LoadRSAPublicKeyFromDisk load public key
func LoadRSAPublicKeyFromDisk(location string) (*rsa.PublicKey, error) {
keyData, e := ioutil.ReadFile(location)
if e != nil {
panic(e.Error())
}
return jwt.ParseRSAPublicKeyFromPEM(keyData)
}