From d6963f2017a77ccdd9d67e94e2406123f3451927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Tue, 30 Sep 2014 12:19:06 +0200 Subject: [PATCH] map JWK parameters to local BigInteger --- src/crypto/public_key/rsa.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 56eb6d63..eb5de534 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -183,7 +183,19 @@ function RSA() { var q = privKey.q; var qi = privKey.qi; - // TODO: map JWK parameters to local BigInteger type system? + // map JWK parameters to local BigInteger type system + var key = new keyObject(); + key.n = new BigInteger(util.hexstrdump(base64(n)), 16); + key.ee = new BigInteger(E, 16); + key.d = new BigInteger(util.hexstrdump(base64(d)), 16); + key.p = new BigInteger(util.hexstrdump(base64(p)), 16); + key.q = new BigInteger(util.hexstrdump(base64(q)), 16); + key.u = key.p.modInverse(key.q); + + function base64(base64url) { + return base64url.replace(/-/g, '+').replace(/_/g, '/') + } + // TODO: add async style callback }