diff --git a/lib/node.js b/lib/node.js index 4607a4c..dd82436 100644 --- a/lib/node.js +++ b/lib/node.js @@ -5,7 +5,7 @@ */ 'use strict'; -var cryptoc = {}; +var cryptoc = module.exports; var rsaExtra = require('./rsa-extra'); var rsaForge = require('./rsa-forge'); var ursac; @@ -40,5 +40,3 @@ Object.keys(rsaForge).forEach(function (key) { cryptoc[key] = rsaForge[key]; } }); - -module.exports.cryptoc = cryptoc; diff --git a/lib/rsa-forge.js b/lib/rsa-forge.js index 233fb76..a617e99 100644 --- a/lib/rsa-forge.js +++ b/lib/rsa-forge.js @@ -28,7 +28,7 @@ function importPublicKey(publicKey) { } */ -var forgec = { +var forgec = module.exports = { @@ -126,5 +126,3 @@ var forgec = { }; - -return forgec; diff --git a/lib/rsa-ursa.js b/lib/rsa-ursa.js index 8c81b7e..4011784 100644 --- a/lib/rsa-ursa.js +++ b/lib/rsa-ursa.js @@ -6,7 +6,7 @@ function notToJson() { return undefined; } -var ursac = { +var ursac = module.exports = { @@ -37,7 +37,7 @@ var ursac = { // Generate New Keypair // , generateKeypair: function (bitlen, exp, options, cb) { - var keypair = ursa.generatePrivateKey(bitlen || 2048, exp || 6553); + var keypair = ursa.generatePrivateKey(bitlen || 2048, exp || 65537); keypair.toJSON = notToJson; @@ -116,5 +116,3 @@ var ursac = { }; - -return ursac; diff --git a/node.js b/node.js index 73685f5..2b17bcc 100644 --- a/node.js +++ b/node.js @@ -20,7 +20,7 @@ function create(deps) { var forge = require("node-forge"); return new Buffer(forge.util.bytesToHex(bytes), "hex"); }; - RSA._internal = require('./lib/node').create(deps); + RSA._internal = require('./lib/node');//.create(deps); RSA.thumbprint = function (jwk) { jwk = jwk.privateKeyJwk || jwk.publicKeyJwk || jwk; diff --git a/tests/generate-key.js b/tests/generate-key.js new file mode 100644 index 0000000..f072b14 --- /dev/null +++ b/tests/generate-key.js @@ -0,0 +1,42 @@ +'use strict'; + +var RSA = require('../').RSA; + +console.log('RSA'); +console.log(RSA); + +RSA.generateKeypair(null, null, null, function (keys) { + console.log(''); + console.log('keys'); + console.log(keys); + + if (!keys.privateKeyJwk) { + throw new Error("Expected privateKeyJwk, but it is missing"); + } + + if ( + keys.publicKeyJwk + || keys.privateKeyPem + || keys.publicKeyPem + || keys.thumbprint + || keys._ursa + || keys._forge + ) { + console.error(keys); + throw new Error("Got unexpected keys"); + } + + var options = { + public: true // export public keys + , pem: true // export pems + , jwk: false // export jwks + , internal: true // preserve internal intermediate formats (_ursa, _forge) + , thumbprint: true // JWK sha256 thumbprint + }; + RSA.generateKeypair(512, 65537, options, function (keys) { + console.log(''); + console.log('keys'); + console.log(keys); + }); + +});