mirror of
https://git.coolaj86.com/coolaj86/old-keypairs.js
synced 2025-03-14 12:20:42 +00:00
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' }
- options example
Keypairs.import(options)
- options example
{ pem: '...' }
- options example
Keypairs.export(options)
- options example
{ jwk: jwk }
- options example
{ jwk: jwk, public: true }
- options example
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.
Description
Interchangeably use RSA & ECDSA with PEM and JWK for Signing, Verifying, CSR generation and JWT and JOSE. Ugh... that was a mouthful. :)
Languages
JavaScript
100%