node-rsa-keypair
Generates a RSA keypair using native OpenSSL library.
This is a fork of rsa-keygen with support for encrypting the generated private key with a given pass phrase. The dependencies have also been updated as per the pull request Update deps by omsmith and calvinmetcalf which was not merged in to the original rsa-keygen.
This code is loosely based on ursa RSA generation code.
Thanks to all the developers who have contributed to the above projects.
N-API Example
The module and code also serves as a simple example to create native addon module in C/C++ using N-API.
Upgrade Notes
Version 2.x uses N-API. For older node versions that do not support N-API, use version 1.0.1:
npm install --save rsa-keypair@1.0.1
History
The node crypto
library has encrypt and decrypt functions, we don't need to rely on any external libraries for public-key cryptography.
Usage
Install the library using npm:
npm install --save rsa-keypair
Or install using yarn:
yarn add rsa-keypair
Use in your code:
var rsaKeyPair = ;var keys = rsaKeyPair;
ES6:
;const keys = rsaKeyPair;
API
/** * Generate RSA key pair. * @param * @param * @param * @return */;
Examples
var crypto = ;var rsaKeyPair = ; var keys = rsaKeyPair; var result = crypto;// <Crypted Buffer> var plaintext = crypto;// Hello world!
var crypto = ;var rsaKeyPair = ; var keys = rsaKeyPair;// Generates a 4096-bit RSA key pair with "top secret" as the pass phrase to encrypt the private key var result = crypto;// <Crypted Buffer> var plaintext = crypto;// Hello world!
var rsaKeyPair = ; var keys = rsaKeyPair;// Generates a 4096-bit RSA key pair with "top secret" as the pass phrase to encrypt the private key var publicKeyStr = keyspublicKey;// The public key string in PEM format which may be written to a file var privateKeyStr = keysprivateKey;// The encrypted private key in PEM format which may be written to a file
Develop
git clone https://github.com/sunjith/node-rsa-keypaircd node-rsa-keypair # Note: You may use yarn instead of npm in each of the following commands # Install dependencies and build npm install # Build only npm start # Run tests npm run test