Skip to content

Commit

Permalink
Merge pull request #5 from coolaj86/patch-3
Browse files Browse the repository at this point in the history
generate keys w/ ursa, fallback to node-forge
  • Loading branch information
michielbdejong committed May 28, 2015
2 parents 03257b8 + 286ff36 commit ff3e8b4
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 ff3e8b4

Please sign in to comment.