Interchangeably use RSA & ECDSA with PEM and JWK for Signing, Verifying, CSR generation and JWT and JOSE. Ugh... that was a mouthful. :)
Go to file
AJ ONeal 7591e3fbdd begin spec 2018-05-10 15:19:09 -06:00
README.md begin spec 2018-05-10 15:19:09 -06:00

README.md

Keypairs™ for node.js

JavaScript RSA and ECDSA utils that work on Windows, Mac, and Linux with or without C compiler.

There are many different RSA and ECDSA libraries for node and it seems like they're all incompatible in different ways. This isn't yet another library, but rather one to rule them all and bind them.

Features

  • RSA
  • [] ECDSA (in-progress)
  • generate keypair
  • export to JWK
  • import from JWK
  • export to PEM
  • import from PEM
  • sign JWS
  • generate CSR (DER as PEM or base64url)

API

  • Keypairs.generate(options)
    • options example { type: 'RSA' || 'ECDSA', bitlength: 2048 || 256 }
  • Keypairs.import(options)
    • options example { pem: '...', crv: 'P-256' || 'ECC', bitlength: 2048 || 256 }
  • Keypairs.export(options)
    • options example { private: true || false, pem: true || false }
  • Keypairs.jws.sign(options)
    • options example { keypair, header, protected, payload }
  • Keypairs.csr.generate(options)
    • options example { keypair, [ 'example.com' ] }

keypair can be any object with any of these keys publicKeyPem, privateKeyPem, publicKeyJwk, privateKeyJwk.

Examples

These are quick examples of how to use the library. If you have a specific question, please open an issue.

Keypairs.generate(options)

Simple RSA

return Keypairs.generate({
  type: 'RSA'
, bitlength: 2048
}).then(function (keypair) {

  // we won't bother describing this object
  // because it's only useful once exported

});

Advanced RSA

return Keypairs.generate({
  type: 'RSA'
, bitlength: 2048 // or 4096
, exponent: 65537 // don't change this
, public: true    // pre-cache public key
, pem: true       // pre-export the PEM
, internal: true  // pre-cache internal representations
}).then(function (keypair) {

  // we won't bother describing this object
  // because it's only useful once exported

});

Keypairs.export(options)

Keypairs.import(options)

Keypairs.jws.sign(options)

Keypairs.csr.generate(options)