What is jwk-to-pem?
The jwk-to-pem npm package is used to convert JSON Web Keys (JWK) to PEM format. This is particularly useful for cryptographic operations where PEM format is required, such as verifying JWTs, encrypting/decrypting data, and more.
What are jwk-to-pem's main functionalities?
Convert JWK to PEM
This feature allows you to convert a JSON Web Key (JWK) to PEM format. The code sample demonstrates how to import the jwk-to-pem package, define a JWK object, and convert it to PEM format.
const jwkToPem = require('jwk-to-pem');
const jwk = {
kty: 'RSA',
n: '0vx7agoebGcQSuuPiLJXZptN1R5Vb1nJ2sT7J4G...'
e: 'AQAB'
};
const pem = jwkToPem(jwk);
console.log(pem);
Convert JWK to PEM with options
This feature allows you to convert a JWK to PEM format with additional options. The code sample shows how to specify options such as converting to a private key PEM format.
const jwkToPem = require('jwk-to-pem');
const jwk = {
kty: 'RSA',
n: '0vx7agoebGcQSuuPiLJXZptN1R5Vb1nJ2sT7J4G...'
e: 'AQAB'
};
const options = { private: true };
const pem = jwkToPem(jwk, options);
console.log(pem);
Other packages similar to jwk-to-pem
node-jose
The node-jose package is a comprehensive library for JSON Object Signing and Encryption (JOSE) and JSON Web Token (JWT) standards. It includes functionality for converting JWK to PEM, but also offers a wide range of other cryptographic operations. Compared to jwk-to-pem, node-jose is more feature-rich and supports a broader set of use cases.
jose
The jose package is another library that provides support for JSON Web Algorithms (JWA), JSON Web Keys (JWK), JSON Web Signatures (JWS), and JSON Web Encryption (JWE). It includes functionality for converting JWK to PEM and is known for its modern API and comprehensive documentation. Compared to jwk-to-pem, jose offers a more extensive set of cryptographic tools and utilities.
jwk-to-pem
Convert a json web key to a PEM for use by OpenSSL or crytpo
.
Install
npm install jwk-to-pem --save
Usage
var jwkToPem = require('jwk-to-pem'),
jwt = require('jsonwebtoken');
var jwk = { kty: 'EC', crv: 'P-256', x: '...', y: '...' },
pem = jwkToPem(jwk);
jwt.verify(token, pem);
Support
key type | support level |
---|
RSA | all RSA keys |
EC | P-256, P-384, and P-521 curves |
Contributing
-
Fork the repository. Committing directly against this repository is
highly discouraged.
-
Make your modifications in a branch, updating and writing new unit tests
as necessary in the spec
directory.
-
Ensure that all tests pass with npm test
-
rebase
your changes against master. Do not merge.
-
Submit a pull request to this repository. Wait for tests to run and someone
to chime in.
Code Style
This repository is configured with EditorConfig, jscs
and JSHint rules.