rsa-key-gen
v0.6.1
Published
rsa key pair and certificate generator
Downloads
71
Readme
rsa-key-gen
An implementation of openssl genrsa for node.
It makes use of pem module which is dependant upon openssl binary to work as is a wrapper to the command line tool.
Install
$ npm install rsa-key-gen
Usage
rsaKeyGen.generateKeyPair(options, [callback])
(Callback) with error and result signature
options
:
bits
key length in bitscipher
default:aes256
see openssl man page for valid optionspassword
: string password for key pair
If no options parameter is used bits defaults to 4096 and cipher to 'aes256'
Example
const rsaKeyGen = require('rsa-key-gen');
const options = {
bits: 4096,
cipher: 'camellia256',
password: 'secret'
};
rsaKeyGen.generateKeyPair(options, (err, result) => {
if (err) {
throw err
}
// Print keypair to console
console.log('%s\n\n%s', result.private, result.public);
});
rsaKeyGen.generateCertificate(options, [callback])
(Callback) with error and result signature
options
selfSigned
booleanbits
length in bits for certificate
If no options parameter is used bits defaults to 4096 and selfSigned to true
Other valid options are described in the pem modules docs
const options = {
bits: 4096,
selfSigned: true
};
rsaKeyGen.generateCertificate(options, (err, result) => {
if (err) {
throw err
}
// Print cert artifacts to console
console.log('%s\n\n%s', result.clientKey, result.certificate);
console.log('%s\n\n%s', result.csr, result.serviceKey);
});
rsaKeyGen.setOpenSSLPath(path)
path
custom location of openSSL path
Caveat with this method must be called in between calls to different binaries as value is cached by node's require
rsaKeyGen.setOpenSSLPath('custom/path/to/openssl');
Install rsa-gen cli
npm i rsa-key-gen -g
Todo
- improve docs
- improve validation of incoming parameters