Skip to content

simon-p-r/rsa-key-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published