Skip to content

Commit 30d5174

Browse files
authored
feat(jwt): add parsing rsa key from string (#100)
1 parent 1696a04 commit 30d5174

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

jwt/key_store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ func (ks *KeyStore) LoadPrivateKey(path string) error {
100100
return nil
101101
}
102102

103+
func (ks *KeyStore) LoadPrivateKeyFromString(str string) error {
104+
pem, err := base64.StdEncoding.DecodeString(str)
105+
if err != nil {
106+
return err
107+
}
108+
key, err := jwt.ParseRSAPrivateKeyFromPEM(pem)
109+
if err != nil {
110+
return err
111+
}
112+
113+
ks.PrivateKey = key
114+
return nil
115+
}
116+
103117
func (ks *KeyStore) GenerateKeys() error {
104118
reader := rand.Reader
105119
bitSize := 2048

0 commit comments

Comments
 (0)