diff --git a/lib/help/asn1/index.js b/lib/help/asn1/index.js index ff7e357c9e..1684c6bb55 100644 --- a/lib/help/asn1/index.js +++ b/lib/help/asn1/index.js @@ -27,3 +27,4 @@ const RSAPublicKey = asn1.define('RSAPublicKey', require('./rsa_public_key')) types.set('RSAPublicKey', RSAPublicKey) module.exports = types +module.exports.bignum = asn1.bignum diff --git a/lib/help/key_utils.js b/lib/help/key_utils.js index c3ff9a2397..b88c911dc0 100644 --- a/lib/help/key_utils.js +++ b/lib/help/key_utils.js @@ -8,6 +8,7 @@ const asn1 = require('./asn1') const computePrimes = require('./rsa_primes') const { OKP_CURVES, EC_CURVES } = require('./consts') +const BN = asn1.bignum const oidHexToCurve = new Map([ ['06082a8648ce3d030107', 'P-256'], ['06052b8104000a', secp256k1], @@ -212,14 +213,14 @@ const jwkToPem = { return RSAPrivateKey.encode({ version: 0, - n: base64url.decodeToBuffer(jwk.n), - e: base64url.decodeToBuffer(jwk.e), - d: base64url.decodeToBuffer(jwk.d), - p: base64url.decodeToBuffer(jwk.p), - q: base64url.decodeToBuffer(jwk.q), - dp: base64url.decodeToBuffer(jwk.dp), - dq: base64url.decodeToBuffer(jwk.dq), - qi: base64url.decodeToBuffer(jwk.qi) + n: new BN(base64url.decodeToBuffer(jwk.n)), + e: new BN(base64url.decodeToBuffer(jwk.e)), + d: new BN(base64url.decodeToBuffer(jwk.d)), + p: new BN(base64url.decodeToBuffer(jwk.p)), + q: new BN(base64url.decodeToBuffer(jwk.q)), + dp: new BN(base64url.decodeToBuffer(jwk.dp)), + dq: new BN(base64url.decodeToBuffer(jwk.dq)), + qi: new BN(base64url.decodeToBuffer(jwk.qi)) }, 'pem', { label: 'RSA PRIVATE KEY' }) }, public (jwk) { @@ -227,8 +228,8 @@ const jwkToPem = { return RSAPublicKey.encode({ version: 0, - n: base64url.decodeToBuffer(jwk.n), - e: base64url.decodeToBuffer(jwk.e) + n: new BN(base64url.decodeToBuffer(jwk.n)), + e: new BN(base64url.decodeToBuffer(jwk.e)) }, 'pem', { label: 'RSA PUBLIC KEY' }) } },