AJ ONeal 9537737d19 | ||
---|---|---|
README.md | ||
index.js | ||
package.json |
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 }
- options example
Keypairs.import(options)
- options example
{ pem: '...', crv: 'P-256' || 'ECC', bitlength: 2048 || 256 }
- options example
Keypairs.export(options)
- options example
{ private: true || false, pem: true || false }
- options example
Keypairs.jws.sign(options)
- options example
{ keypair, header, protected, payload }
- options example
Keypairs.csr.generate(options)
- options example
{ keypair, [ 'example.com' ] }
- options example
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
});