function genKeys(cb) {
    // gen private
    cp.exec('openssl genrsa 2048', function(err, priv, stderr) {
        // tmp file
        var randomfn = './' + Math.random().toString(36).substring(7);
        fs.writeFileSync(randomfn, priv);
        // gen public
        cp.exec('openssl rsa -in ' + randomfn + ' -pubout', function(err, pub, stderr) {
            // delete tmp file
            fs.unlinkSync(randomfn);
            // callback
            privateKEY = priv;
            publicKEY = pub;
            cb(JSON.stringify({ public: pub, private: priv }, null, 4));
        });

    });
}
// Genrate public and private key pair programmetically
Genrate public and private key pair programmetically
Genrate public and private key pair programmetically
function genKeys(cb) {
    cp.exec('openssl genrsa 2048', function(err, priv, stderr) {
        var randomfn = './' + Math.random().toString(36).substring(7);
        fs.writeFileSync(randomfn, priv);
        cp.exec('openssl rsa -in ' + randomfn + ' -pubout', function(err, pub, stderr) {
            fs.unlinkSync(randomfn);
            privateKEY = priv;
            publicKEY = pub;
            cb(JSON.stringify({ public: pub, private: priv }, null, 4));
        });
    });
}
function genKeys ( cb ) { cp . exec ( 'openssl genrsa 2048' , function ( err , priv , stderr ) { var randomfn = './' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) ; fs . writeFileSync ( randomfn , priv ) ; cp . exec ( 'openssl rsa -in ' + randomfn + ' -pubout' , function ( err , pub , stderr ) { fs . unlinkSync ( randomfn ) ; privateKEY = priv ; publicKEY = pub ; cb ( JSON . stringify ( { public : pub , private : priv } , null , 4 ) ) ; } ) ; } ) ; }
Genrate public and private key pair programmetically
Genrate public and private key pair programmetically
// gen private // tmp file // gen public // delete tmp file // callback