diff --git a/lib/crypto-util.js b/lib/crypto-util.js index f8a3634..88be57d 100644 --- a/lib/crypto-util.js +++ b/lib/crypto-util.js @@ -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)