How to use the rsa function from node-forge
Find comprehensive JavaScript node-forge.rsa code examples handpicked from public code repositorys.
GitHub: notimobi/wildduck
![notimobi profile picture](/notimobi.png?size=40)
59 60 61 62 63 64 65 66 67 68
return done(); }); } // Fallback to Forge forge.rsa.generateKeyPair({ bits: 2048, workers: -1 }, (err, keypair) => { if (err) { err.code = 'KeyGenereateError'; return callback(err); }
GitHub: juhoen/hybrid-crypto-js
![juhoen profile picture](/juhoen.png?size=40)
14 15 16 17 18 19 20 21 22 23
var helpers = require('./helpers'); var forge = require('node-forge'); var pki = forge.pki, rsa = forge.rsa; var _require = require('./constants'), DEFAULT_MESSAGE_DIGEST = _require.DEFAULT_MESSAGE_DIGEST, DEFAULT_AES_KEY_SIZE = _require.DEFAULT_AES_KEY_SIZE,
+ 3 other calls in file
10 11 12 13 14 15 16 17 18 19
console.log(new Error('Requested crash by endpoint /crash')) process.exit(1) }) router.get('/generatecert', function (req, res, next) { const keys = pki.rsa.generateKeyPair(2048) const cert = pki.createCertificate() cert.publicKey = keys.publicKey res.send({ keys: keys,
GitHub: hyperonecom/h1-cli
![hyperonecom profile picture](/hyperonecom.png?size=40)
1 2 3 4 5 6 7 8 9 10
const forge = require('node-forge'); const ssh2 = require('ssh2'); const generateKey = (comment = 'autogenerated') => new Promise((resolve, reject) => forge.rsa.generateKeyPair({ bits: 2048, workers: -1, }, (err, keypair) => { if (err) return reject(err);
22 23 24 25 26 27 28 29 30 31
}; }catch(E){} // bad form to cb from inside a try if(keypair) return cb(null, keypair); } forge.rsa.generateKeyPair(opts, function(err, pair){ if (err) return cb(err); var keypair = { public: forge.ssh.publicKeyToOpenSSH(pair.publicKey), private: forge.ssh.privateKeyToOpenSSH(pair.privateKey),
18 19 20 21 22 23 24 25 26 27
private: pair.toPrivatePem('utf8') } } catch (err) { // fallback to native JS (Raspberry Pi: 15 min) console.log('fallback to native JS...') let pair = forge.rsa.generateKeyPair(2048) keypair = { public: forge.pki.publicKeyToPem(pair.publicKey), private: forge.pki.privateKeyToPem(pair.privateKey) }
node-forge.pki is the most popular function in node-forge (10287 examples)