Skip to content

Commit

Permalink
generate keys w/ ursa, fallback to node-forge
Browse files Browse the repository at this point in the history
Running the demo went from 89 minutes down to about 3 on raspberry pi.

Related:

* digitalbazaar/forge#263
* https://github.com/letsencrypt/node-acme/issues/22.
  • Loading branch information
AJ ONeal committed May 27, 2015
1 parent 800c26c commit 286ff36
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/crypto-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,22 @@ module.exports = {
///// KEY PAIR MANAGEMENT

generateKeyPair: function(bits) {
var keyPair = forge.pki.rsa.generateKeyPair({bits: bits, e: 0x10001});
var ursa, keyPair;

try {
ursa = require('ursa');
} catch(e) {
// ignore
}

if (ursa) {
// This takes between 2 and 6 seconds on a raspberry pi
keyPair = ursa.generatePrivateKey(bits, 0x10001);
return module.exports.importPemPrivateKey(keyPair.toPrivatePem('utf8'));
}

// This takes 20-30 minutes on a raspberry pi
keyPair = forge.pki.rsa.generateKeyPair({bits: bits, e: 0x10001});
return {
privateKey: exportPrivateKey(keyPair.privateKey),
publicKey: exportPublicKey(keyPair.publicKey)
Expand Down

0 comments on commit 286ff36

Please sign in to comment.