forked from Qihoo360/wayne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsa_key.go
44 lines (35 loc) · 831 Bytes
/
rsa_key.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 initial
import (
"io/ioutil"
"path/filepath"
"github.com/astaxie/beego"
"github.com/dgrijalva/jwt-go"
"github.com/Qihoo360/wayne/src/backend/apikey"
)
func InitRsaKey() {
privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(readKey("RsaPrivateKey"))
if err != nil {
panic(err)
}
apikey.RsaPrivateKey = privateKey
publicKey, err := jwt.ParseRSAPublicKeyFromPEM(readKey("RsaPublicKey"))
if err != nil {
panic(err)
}
apikey.RsaPublicKey = publicKey
}
func readKey(key string) []byte {
filename := beego.AppConfig.String(key)
// get the abs
// which will try to find the 'filename' from current workind dir too.
pem, err := filepath.Abs(filename)
if err != nil {
panic(err)
}
// read the raw contents of the file
data, err := ioutil.ReadFile(pem)
if err != nil {
panic(err)
}
return data
}