Simple RSA key conversion from PEM-format to JWK-format with no dependencies on Node.js or Web Crypto API. Works in react-native.
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
Read section 6.3 in rfc7518.
The lib react-native-rsa-native generates keys in PEM format but did not support exporting to JWK format. Hence this helper lib.