rsa-key-gen

0.6.1 • Public • Published

rsa-key-gen

Current Version dependency Status devDependency Status Build Status Windows Build Status Coveralls

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 bits
  • cipher default: aes256 see openssl man page for valid options
  • password: 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 boolean
  • bits 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

Readme

Keywords

none

Package Sidebar

Install

npm i rsa-key-gen

Weekly Downloads

14

Version

0.6.1

License

BSD-3-Clause

Unpacked Size

19.9 kB

Total Files

9

Last publish

Collaborators

  • simon-p-r