{"id":19163264,"url":"https://github.com/oada/rsa-pem-to-jwk","last_synced_at":"2025-04-10T05:05:54.548Z","repository":{"id":24697412,"uuid":"28108747","full_name":"OADA/rsa-pem-to-jwk","owner":"OADA","description":"Converts a public or private PEM encoded RSA key to JWK (JSON Web Key)","archived":false,"fork":false,"pushed_at":"2023-06-05T06:17:31.000Z","size":32,"stargazers_count":60,"open_issues_count":8,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-10T05:05:52.739Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OADA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-16T22:03:59.000Z","updated_at":"2023-12-06T12:07:39.000Z","dependencies_parsed_at":"2025-01-16T09:17:08.553Z","dependency_job_id":"8b8f0a81-e742-4e8d-82a2-8da5fa5ee8a3","html_url":"https://github.com/OADA/rsa-pem-to-jwk","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"d146e50583eb595e8f8c125c2ef30cf19ea7d328"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Frsa-pem-to-jwk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Frsa-pem-to-jwk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Frsa-pem-to-jwk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Frsa-pem-to-jwk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OADA","download_url":"https://codeload.github.com/OADA/rsa-pem-to-jwk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161273,"owners_count":21057555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:14:40.642Z","updated_at":"2025-04-10T05:05:54.503Z","avatar_url":"https://github.com/OADA.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/OADA/rsa-pem-to-jwk.svg)](https://travis-ci.org/OADA/rsa-pem-to-jwk)\n[![Coverage Status](https://coveralls.io/repos/OADA/rsa-pem-to-jwk/badge.png?branch=master)](https://coveralls.io/r/OADA/rsa-pem-to-jwk?branch=master)\n[![Dependency Status](https://david-dm.org/oada/rsa-pem-to-jwk.svg)](https://david-dm.org/oada/rsa-pem-to-jwk)\n[![License](http://img.shields.io/:license-Apache%202.0-green.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)\n\n# Table of Contents\n\n- [rsa-pem-to-jwk](#rsa-pem-to-jwk)\n- [Getting Started](#getting-started)\n  - [Installation](#installation)\n  - [Running the tests, coverage, and style checks](#running-the-tests-coverage-and-style-checks)\n  - [PEM Format](#pem-format)\n    - [Private Keys](#private-keys)\n    - [Public Keys](#public-keys)\n- [API Reference](#api-reference)\n  - [rsaPemToJwk(pem, extraKeys, type)](#rsapemtojwkpem-extrakeys-type)\n    - [Parameters](#parameters)\n    - [Usage Example](#usage-example)\n\n# rsa-pem-to-jwk\n\nConverts PEM encoded RSA public and private keys to the [JWK (JSON Web\nKey)][jwk] format.\n\nFor example, given the following PEM encoded RSA key:\n\n```\n-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQDfn1nKQshOSj8xw44oC2klFWSNLmK3BnHONCJ1bZfq0EQ5gIfg\ntlvB+Px8Ya+VS3OnK7Cdi4iU1fxO9ktN6c6TjmmmFevk8wIwqLthmCSF3r+3+h4e\nddj7hucMsXWv05QUrCPoL6YUUz7Cgpz7ra24rpAmK5z7lsV+f3BEvXkrUQIDAQAB\nAoGAC0G3QGI6OQ6tvbCNYGCqq043YI/8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhs\nkURaDwk4+8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh/\nxa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0CQQD13LrBTEDR44ei\nlQ/4TlCMPO5bytd1pAxHnrqgMnWovSIPSShAAH1feFugH7ZGu7RoBO7pYNb6N3ia\nC1idc7yjAkEA6Nfc6c8meTRkVRAHCF24LB5GLfsjoMB0tOeEO9w9Ous1a4o+D24b\nAePMUImAp3woFoNDRfWtlNktOqLel5PjewJBAN9kBoA5o6/Rl9zeqdsIdWFmv4DB\n5lEqlEnC7HlAP+3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhcCQQDb\nW0mOp436T6ZaELBfbFNulNLOzLLi5YzNRPLppfG1SRNZjbIrvTIKVL4N/YxLvQbT\nNrQw+2OdQACBJiEHsdZzAkBcsTk7frTH4yGx0VfHxXDPjfTj4wmD6gZIlcIr9lZg\n4H8UZcVFN95vEKxJiLRjAmj6g273pu9kK4ymXNEjWWJn\n-----END RSA PRIVATE KEY-----\n```\n\nthe following private RSA JWK is returned:\n\n```json\n{\n  \"kty\": \"RSA\",\n  \"n\": \"AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR\",\n  \"e\": \"AQAB\",\n  \"d\": \"C0G3QGI6OQ6tvbCNYGCqq043YI_8MiBl7C5dqbGZmx1ewdJBhMNJPStuckhskURaDwk4-8VBW9SlvcfSJJrnZhgFMjOYSSsBtPGBIMIdM5eSKbenCCjO8Tg0BUh_xa3CHST1W4RQ5rFXadZ9AeNtaGcWj2acmXNO3DVETXAX3x0\",\n  \"p\": \"APXcusFMQNHjh6KVD_hOUIw87lvK13WkDEeeuqAydai9Ig9JKEAAfV94W6Aftka7tGgE7ulg1vo3eJoLWJ1zvKM\",\n  \"q\": \"AOjX3OnPJnk0ZFUQBwhduCweRi37I6DAdLTnhDvcPTrrNWuKPg9uGwHjzFCJgKd8KBaDQ0X1rZTZLTqi3peT43s\",\n  \"dp\": \"AN9kBoA5o6_Rl9zeqdsIdWFmv4DB5lEqlEnC7HlAP-3oo3jWFO9KQqArQL1V8w2D4aCd0uJULiC9pCP7aTHvBhc\",\n  \"dq\": \"ANtbSY6njfpPploQsF9sU26U0s7MsuLljM1E8uml8bVJE1mNsiu9MgpUvg39jEu9BtM2tDD7Y51AAIEmIQex1nM\",\n  \"qi\": \"XLE5O360x-MhsdFXx8Vwz4304-MJg-oGSJXCK_ZWYOB_FGXFRTfebxCsSYi0YwJo-oNu96bvZCuMplzRI1liZw\"\n}\n```\n\nalternatively, the PEM can also be converted to a public RSA JWK:\n\n```json\n{\n  \"kty\": \"RSA\",\n  \"n\": \"AN-fWcpCyE5KPzHDjigLaSUVZI0uYrcGcc40InVtl-rQRDmAh-C2W8H4_Hxhr5VLc6crsJ2LiJTV_E72S03pzpOOaaYV6-TzAjCou2GYJIXev7f6Hh512PuG5wyxda_TlBSsI-gvphRTPsKCnPutrbiukCYrnPuWxX5_cES9eStR\",\n  \"e\": \"AQAB\"\n}\n```\n\n# Getting Started\n\n## Installation\nThe library can be installed with `npm` using\n```sh\n$ npm install rsa-pem-to-jwk\n```\n\n## Running the tests, coverage, and style checks\nThe module's tests are run with:\n```sh\n$ npm test\n```\n\nThe coverage report is generated with:\n```sh\n$ npm run cover\n```\n\n`jshint` (lint) and `jscs` (style) is automated with gulp:\n```sh\n$ gulp lint\n$ gulp style\n```\n\nor just\n```sh\n$ gulp\n```\n\n## PEM Format\n\nThis module expects the input RSA keys to be in \"PEM\" format. Most tools agree\non what this means for private keys but some tools have different definitions\nfor public keys.\n\n### Private Keys\n\nBoth OpenSSH and OpenSSL use the same RSA private key PEM format. Below is an\nexample of generating such a PEM of a 2048 bit RSA private key with each tool:\n\n**OpenSSL:**\n```sh\n$ openssl genrsa -out private.pem 2048\n```\n\n**OpenSSH:**\n```sh\n$ ssh-keygen -t rsa -b 2048 -m PEM -f private.pem\n```\n\n### Public Keys\n\nThe expected PEM format for public keys is `RSAPublicKey`. This is the default\noutput PEM format for the OpenSSH key generation tool but not for OpenSSL\n(requires -RSAPublicKey_out flag). Below is an example of generating the public\nkey from a RSA private key PEM with each tool:\n\n**OpenSSL**:\n```sh\n$ openssl rsa -in private.pem -RSAPublicKey_out -out public.pem\n```\n\n**OpenSSH**:\n```sh\n$ ssh-keygen -f private.pem -e -m PEM \u003e public.pem\n```\n\n# API Reference\n\n## rsaPemToJwk(pem, extraKeys, type)\nConverts PEM encoded RSA public and private keys to the [JWK (JSON Web\nKey)][jwk] format.\n\n### Parameters\n`pem` {String} of a PEM encoded RSA public or private key.\n\n`extraKeys` {Object} whose keys appear in the JWK body. **Default**: *{}*\n\n`type` {String} equal to:\n  - *public* -- JWK will only contain the public portions of the RSA key.\n  - *private* -- JWK will contain both the public and private portions of the RSA\n    key.\n\n    **Default**: *type of input PEM*\n\n### Usage Example\n```javascript\nvar fs = require('fs');\nvar rsaPemToJwk = require('rsa-pem-to-jwk');\n\nvar pem = fs.readFileSync('privateKey.pem');\n\nvar jwk = rsaPemToJwk(pem, {use: 'sig'}, 'public');\n```\n\n[jwk]: https://tools.ietf.org/id/draft-ietf-jose-json-web-key.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Frsa-pem-to-jwk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foada%2Frsa-pem-to-jwk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Frsa-pem-to-jwk/lists"}