How to use the rsa function from node-forge

Find comprehensive JavaScript node-forge.rsa code examples handpicked from public code repositorys.

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);
    }
fork icon245
star icon0
watch icon0

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,
fork icon40
star icon126
watch icon6

+ 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,
fork icon10
star icon4
watch icon9

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);
fork icon4
star icon6
watch icon4

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),
fork icon0
star icon2
watch icon3

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)
  }
fork icon0
star icon1
watch icon2