Gathering detailed insights and metrics for rsa-pem-to-jwk
Gathering detailed insights and metrics for rsa-pem-to-jwk
Gathering detailed insights and metrics for rsa-pem-to-jwk
Gathering detailed insights and metrics for rsa-pem-to-jwk
Converts a public or private PEM encoded RSA key to JWK (JSON Web Key)
npm install rsa-pem-to-jwk
Typescript
Module System
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
60 Stars
19 Commits
9 Forks
8 Watchers
1 Branches
9 Contributors
Updated on Dec 06, 2023
Latest Version
1.1.3
Package Id
rsa-pem-to-jwk@1.1.3
Size
10.16 kB
NPM Version
1.4.28
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
8
Converts PEM encoded RSA public and private keys to the JWK (JSON Web Key) format.
For example, given the following PEM encoded RSA key:
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDfn1nKQshOSj8xw44oC2klFWSNLmK3BnHONCJ1bZfq0EQ5gIfg
tlvB+Px8Ya+VS3OnK7Cdi4iU1fxO9ktN6c6TjmmmFevk8wIwqLthmCSF3r+3+h4e
ddj7hucMsXWv05QUrCPoL6YUUz7Cgpz7ra24rpAmK5z7lsV+f3BEvXkrUQIDAQAB
AoGAC0G3QGI6OQ6tvbCNYGCqq043YI/8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhs
kURaDwk4+8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh/
xa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0CQQD13LrBTEDR44ei
lQ/4TlCMPO5bytd1pAxHnrqgMnWovSIPSShAAH1feFugH7ZGu7RoBO7pYNb6N3ia
C1idc7yjAkEA6Nfc6c8meTRkVRAHCF24LB5GLfsjoMB0tOeEO9w9Ous1a4o+D24b
AePMUImAp3woFoNDRfWtlNktOqLel5PjewJBAN9kBoA5o6/Rl9zeqdsIdWFmv4DB
5lEqlEnC7HlAP+3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhcCQQDb
W0mOp436T6ZaELBfbFNulNLOzLLi5YzNRPLppfG1SRNZjbIrvTIKVL4N/YxLvQbT
NrQw+2OdQACBJiEHsdZzAkBcsTk7frTH4yGx0VfHxXDPjfTj4wmD6gZIlcIr9lZg
4H8UZcVFN95vEKxJiLRjAmj6g273pu9kK4ymXNEjWWJn
-----END RSA PRIVATE KEY-----
the following private RSA JWK is returned:
1{ 2 "kty": "RSA", 3 "n": "AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR", 4 "e": "AQAB", 5 "d": "C0G3QGI6OQ6tvbCNYGCqq043YI_8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhskURaDwk4-8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh_xa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0", 6 "p": "APXcusFMQNHjh6KVD_hOUIw87lvK13WkDEeeuqAydai9Ig9JKEAAfV94W6Aftka7tGgE7ulg1vo3eJoLWJ1zvKM", 7 "q": "AOjX3OnPJnk0ZFUQBwhduCweRi37I6DAdLTnhDvcPTrrNWuKPg9uGwHjzFCJgKd8KBaDQ0X1rZTZLTqi3peT43s", 8 "dp": "AN9kBoA5o6_Rl9zeqdsIdWFmv4DB5lEqlEnC7HlAP-3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhc", 9 "dq": "ANtbSY6njfpPploQsF9sU26U0s7MsuLljM1E8uml8bVJE1mNsiu9MgpUvg39jEu9BtM2tDD7Y51AAIEmIQex1nM", 10 "qi": "XLE5O360x-MhsdFXx8Vwz4304-MJg-oGSJXCK_ZWYOB_FGXFRTfebxCsSYi0YwJo-oNu96bvZCuMplzRI1liZw" 11}
alternatively, the PEM can also be converted to a public RSA JWK:
1{ 2 "kty": "RSA", 3 "n": "AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR", 4 "e": "AQAB" 5}
The library can be installed with npm
using
1$ npm install rsa-pem-to-jwk
The module's tests are run with:
1$ npm test
The coverage report is generated with:
1$ npm run cover
jshint
(lint) and jscs
(style) is automated with gulp:
1$ gulp lint 2$ gulp style
or just
1$ gulp
This module expects the input RSA keys to be in "PEM" format. Most tools agree on what this means for private keys but some tools have different definitions for public keys.
Both OpenSSH and OpenSSL use the same RSA private key PEM format. Below is an example of generating such a PEM of a 2048 bit RSA private key with each tool:
OpenSSL:
1$ openssl genrsa -out private.pem 2048
OpenSSH:
1$ ssh-keygen -t rsa -b 2048 -m PEM -f private.pem
The expected PEM format for public keys is RSAPublicKey
. This is the default
output PEM format for the OpenSSH key generation tool but not for OpenSSL
(requires -RSAPublicKey_out flag). Below is an example of generating the public
key from a RSA private key PEM with each tool:
OpenSSL:
1$ openssl rsa -in private.pem -RSAPublicKey_out -out public.pem
OpenSSH:
1$ ssh-keygen -f private.pem -e -m PEM > public.pem
Converts PEM encoded RSA public and private keys to the JWK (JSON Web Token) format.
pem
{String} of a PEM encoded RSA public or private key.
extraKeys
{Object} whose keys appear in the JWK body. Default: {}
type
{String} equal to:
public -- JWK will only contain the public portions of the RSA key.
private -- JWK will contain both the public and private portions of the RSA key.
Default: type of input PEM
1var fs = require('fs'); 2var rsaPemToJwk = require('rsa-pem-to-jwk'); 3 4var pem = fs.readFileSync('privateKey.pem'); 5 6var jwk = rsaPemToJwk(pem, {use: 'sig'}, 'public');
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More