Interchangeably use RSA & ECDSA with PEM and JWK for Signing, Verifying, CSR generation and JOSE. Ugh... that was a mouthful. :)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AJ ONeal 265977e2c0 v1.0.0: just wrap Rasha and Eckles for now 6 months ago
.gitignore v1.0.0: just wrap Rasha and Eckles for now 6 months ago
README.md v1.0.0: just wrap Rasha and Eckles for now 6 months ago
keypairs.js v1.0.0: just wrap Rasha and Eckles for now 6 months ago
package-lock.json v1.0.0: just wrap Rasha and Eckles for now 6 months ago
package.json v1.0.0: just wrap Rasha and Eckles for now 6 months ago

README.md

Keypairs for node.js

Lightweight JavaScript RSA and ECDSA utils that work on Windows, Mac, and Linux using modern node.js APIs (no need for C compiler).

A thin wrapper around Eckles.js (ECDSA) and Rasha.js (RSA).

Features

  • Generate keypairs
    • RSA
    • ECDSA (P-256, P-384)
  • PEM-to-JWK
  • JWK-to-PEM
  • SHA256 JWK Thumbprints
  • JWK fetching. See Keyfetch.js
    • OIDC
    • Auth0

Usage

A brief (albeit somewhat nonsensical) introduction to the APIs:

Keypairs.generate().then(function (jwk) {
  return Keypairs.export({ jwk: jwk }).then(function (pem) {
    return Keypairs.import({ pem: pem }).then(function (jwk) {
      return Keypairs.thumbprint({ jwk: jwk }).then(function (thumb) {
        console.log(thumb);
      });
    });
  });
});

By default ECDSA keys will be used since they’ve had native support in node much longer than RSA has, and they’re smaller, and faster to generate.

API

Each of these return a Promise.

  • Keypairs.generate(options)
    • options example { kty: 'RSA', modulusLength: 2048 }
    • options example { kty: 'ECDSA', namedCurve: 'P-256' }
  • Keypairs.import(options)
    • options example { pem: '...' }
  • Keypairs.export(options)
    • options example { jwk: jwk }
    • options example { jwk: jwk, public: true }
  • Keypairs.thumbprint({ jwk: jwk })

Full Documentation

Keypairs.js provides a 1-to-1 mapping to the Rasha.js and Eckles.js APIs.

The full RSA documentation is at Rasha.js

The full ECDSA documentation is at Eckles.js

Any option you pass to Keypairs will be passed directly to the corresponding API of either Rasha or Eckles.