Convert PEM to JWK for JOSE and OAuth
JWT libraries, OAuth authorization servers and OpenID Connect clients describe keys as JSON Web Keys (JWK, RFC 7517), while OpenSSL and most key generators write PEM. This pem to jwk converter bridges the two. It reads RSA, EC (P-256, P-384, P-521) and Ed25519 keys and writes the matching JWK with the alg, kid and optional use members filled in.
Example
The sample P-256 public key, with use set to sig, converts to:
{
"kty": "EC",
"x": "JrocOMVB3s0sRD_b5ehRYgQ_NQNrPZSYWe-8QUcO6PY",
"y": "SDzzniq7opG2bUyDdodckEjjhVbj-wDKbU4w_paSmGo",
"crv": "P-256",
"alg": "ES256",
"use": "sig",
"kid": "hKbvYSZiIpgeOaJMdd2IADeQHiU8ITjVvd2YwwpcZOg"
}
What gets converted
- PUBLIC KEY (SPKI): becomes a public JWK.
- CERTIFICATE: the public key is extracted, and the certificate itself is added as an
x5centry, which some identity providers expect in their JWKS. - PRIVATE KEY, RSA PRIVATE KEY and EC PRIVATE KEY: become private JWKs with
d(and for RSA alsop,q,dp,dq,qi), unless you tick the public-only option.
The alg is chosen from the key: RS256 for RSA, PS256 for RSA-PSS keys, ES256, ES384 or ES512 by curve, and EdDSA for Ed25519. Paste several blocks at once to convert them together, which is handy for building a JWKS during key rotation.
How the kid is calculated
When the Key ID field is blank, the kid is the RFC 7638 JWK thumbprint: a SHA-256 hash of the required public members in a fixed order. The same public key always gets the same kid, and the private and public forms of a key share it, so verifiers can match tokens to keys reliably.
Common errors and fixes
- "RSA PUBLIC KEY is not supported": convert PKCS#1 public keys to SPKI with
openssl rsa -RSAPublicKey_in -puboutand paste the result. - "Encrypted private keys are not supported": decrypt the key with openssl first.
- "Unsupported EC curve": only the NIST curves P-256, P-384 and P-521 have JWS algorithms here. secp256k1 keys are rejected.
Going the other direction? Use the JWK to PEM converter. To test the JWK, sign a token with the JWT encoder and check it with the JWT verifier.
Privacy
Conversion uses the jose library and WebCrypto in your browser. Private keys are not uploaded, but they do appear in the output box, so clear it when you are done.