...
1 package keyfunc
2
3 import (
4 "crypto/rsa"
5 "fmt"
6 "math/big"
7 )
8
9 const (
10
11 ktyRSA = "RSA"
12 )
13
14
15 func (j *jsonWebKey) RSA() (publicKey *rsa.PublicKey, err error) {
16 if j.Exponent == "" || j.Modulus == "" {
17 return nil, fmt.Errorf("%w: %s", ErrMissingAssets, ktyRSA)
18 }
19
20
21
22
23
24 exponent, err := base64urlTrailingPadding(j.Exponent)
25 if err != nil {
26 return nil, err
27 }
28 modulus, err := base64urlTrailingPadding(j.Modulus)
29 if err != nil {
30 return nil, err
31 }
32
33 publicKey = &rsa.PublicKey{}
34
35
36
37
38
39 publicKey.E = int(big.NewInt(0).SetBytes(exponent).Uint64())
40 publicKey.N = big.NewInt(0).SetBytes(modulus)
41
42 return publicKey, nil
43 }
44
View as plain text