From b9db0442bfdba05dec460ff440b52dbf8d065f7f Mon Sep 17 00:00:00 2001 From: Mitar Date: Fri, 11 Mar 2016 16:30:15 -0800 Subject: [PATCH 1/2] Use ursa node package to generate RSA keys. --- package.json | 3 ++- src/node/algorithms/shared/RSA.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 17c069e..595a2fd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "ecc-jsbn": "0.0.1", "node-forge": "^0.6.20", "polyfill-promise": "^4.0.1", - "sjcl": "^1.0.3" + "sjcl": "^1.0.3", + "ursa": "^0.9.3" }, "optionalDependencies":{ "ecc-qj" : "git+https://github.com/rynomad/ecc.git" diff --git a/src/node/algorithms/shared/RSA.js b/src/node/algorithms/shared/RSA.js index bd444f4..e1ff567 100644 --- a/src/node/algorithms/shared/RSA.js +++ b/src/node/algorithms/shared/RSA.js @@ -1,4 +1,5 @@ var forge = require("node-forge") + , ursa = require("ursa") , pkcsPad1 = new Buffer([48, 130]) , pkcsPad2 = new Buffer([2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130]) @@ -35,7 +36,8 @@ function generate(algorithm){ pos++; } - return forge.rsa.generateKeyPair({bits: algorithm.modulousLength , e: exp}); + var keyPair = ursa.generatePrivateKey(algorithm.modulousLength, exp); + return forge.pki.privateKeyFromPem(keyPair.toPrivatePem('utf8')); } From 4a8c934ba619a99948d42b1922eef82d15e60a9c Mon Sep 17 00:00:00 2001 From: Mitar Date: Fri, 11 Mar 2016 17:25:15 -0800 Subject: [PATCH 2/2] Correctly use ursa. --- src/node/algorithms/shared/RSA.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node/algorithms/shared/RSA.js b/src/node/algorithms/shared/RSA.js index e1ff567..58ddce2 100644 --- a/src/node/algorithms/shared/RSA.js +++ b/src/node/algorithms/shared/RSA.js @@ -37,7 +37,10 @@ function generate(algorithm){ } var keyPair = ursa.generatePrivateKey(algorithm.modulousLength, exp); - return forge.pki.privateKeyFromPem(keyPair.toPrivatePem('utf8')); + return { + privateKey: forge.pki.privateKeyFromPem(keyPair.toPrivatePem('utf8')), + publicKey: forge.pki.publicKeyFromPem(keyPair.toPublicPem('utf8')) + } }