simple-pem2jwk

0.2.4 • Public • Published

simple-pem2jwk

Simple RSA key conversion from PEM-format to JWK-format with no dependencies on Node.js or Web Crypto API. Works in react-native.

Example for private key;

const privateKey = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCA... ...e+BMRbC5SnJpMsfF0luZhvX
-----END RSA PRIVATE KEY-----`

pem2jwk(privateKey)

// Output:
// {
//     p: '...',
//     kty: 'RSA',
//     q: '...',
//     d: '...',
//     e: '...',
//     qi: '...',
//     dp: '...',
//     dq: '...',
//     n: '...'
// }

// It works the same way with public keys but the output only contains parameters n, e and kty

What does the parameters mean?

Read section 6.3 in rfc7518.

Why this lib?

The lib react-native-rsa-native generates keys in PEM format but did not support exporting to JWK format. Hence this helper lib.

Readme

Keywords

Package Sidebar

Install

npm i simple-pem2jwk

Weekly Downloads

170

Version

0.2.4

License

Apache-2.0

Unpacked Size

24.8 kB

Total Files

6

Last publish

Collaborators

  • einarpersson