Thursday, 27 April 2017

How to generate public and private key in nodejs?

Please someone help me in generating public and private keys in nodejs. I've a php code snippet which generates public and private keys. Is there any equivalent way of doing this in nodeJS or meteorJS.

    $config = [
        'private_key_bits' => 2048,
        'private_key_type' => OPENSSL_KEYTYPE_RSA
    ];

    // Create the private and public key.
    $resourceIdentifier = openssl_pkey_new($config);

    openssl_pkey_export($resourceIdentifier, $privateKey);
    $publicKey = openssl_pkey_get_details($resourceIdentifier)['key'];

    $pair = new stdClass();
    $pair->privateKey = $privateKey;
    $pair->publicKey = $publicKey;

    // Clean up the key resource.
    openssl_pkey_free($resourceIdentifier);

    return $pair;



via user3588408

No comments:

Post a Comment