Skip to content

Commit

Permalink
bytes buffer for exponent
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed May 17, 2024
1 parent 7c605ab commit a595daf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/token/generate_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package token

import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"strconv"
"encoding/binary"

"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
Expand All @@ -30,14 +31,22 @@ func (tm *Manager) GenerateRSA(db database.Interface) error {
return err
}

// convert exponent to binary data to encode in base64
e := new(bytes.Buffer)

err = binary.Write(e, binary.BigEndian, int64(privateRSAKey.PublicKey.E))
if err != nil {
return err
}

// abstract the JWK from the public key information
key := api.JWK{
Algorithm: jwt.SigningMethodRS256.Name,
Kid: kid.String(),
Use: "sig",
Kty: "RSA",
N: base64.RawURLEncoding.EncodeToString(privateRSAKey.PublicKey.N.Bytes()),
E: base64.RawURLEncoding.EncodeToString([]byte(strconv.Itoa(privateRSAKey.PublicKey.E))),
E: base64.RawURLEncoding.EncodeToString(e.Bytes()),
}

// create the JWK in the database
Expand Down

0 comments on commit a595daf

Please sign in to comment.