Skip to content

Commit

Permalink
fix: properly pad calculated RSA primes
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jul 29, 2019
1 parent 8d625a1 commit dd121ce
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/help/rsa_primes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const ZERO = BigInt(0)
const ONE = BigInt(1)
const TWO = BigInt(2)

const toJWKParameter = n => base64url.encodeBuffer(Buffer.from(n.toString(16), 'hex'))
const toJWKParameter = (n) => {
const hex = n.toString(16)
return base64url.encodeBuffer(Buffer.from(hex.length % 2 === 1 ? `0${hex}` : hex, 'hex'))
}
const fromBuffer = buf => BigInt(`0x${buf.toString('hex')}`)
const bitLength = n => n.toString(2).length

Expand Down

0 comments on commit dd121ce

Please sign in to comment.