Convert JWK to PEM for OpenSSL and servers
Identity providers publish their signing keys as a JWKS, but many tools, including OpenSSL, nginx, API gateways and older JWT libraries, want PEM. This jwk to pem converter reads RSA, EC and Ed25519 (OKP) JSON Web Keys and writes standard PEM: BEGIN PUBLIC KEY (SPKI) for public keys and BEGIN PRIVATE KEY (PKCS#8) for private ones.
Example
The sample JWKS holds one P-256 key. Converting it gives:
# kid hKbvYSZiIpgeOaJMdd2IADeQHiU8ITjVvd2YwwpcZOg — EC P-256
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJrocOMVB3s0sRD/b5ehRYgQ/NQNr
PZSYWe+8QUcO6PZIPPOeKruikbZtTIN2h1yQSOOFVuP7AMptTjD+lpKYag==
-----END PUBLIC KEY-----
When a JWKS contains several keys, each one gets its own comment line and PEM block, so you can find the key that matches a token's kid header.
Supported keys
- RSA (
kty: "RSA"): needsnande, plusd,p,q,dp,dqandqifor a private key. - EC (
kty: "EC"): curves P-256, P-384 and P-521 withx,yand optionallyd. - OKP (
kty: "OKP"): Ed25519 keys withxand optionallyd.
If a key has no alg, one is inferred from its type and curve. Members such as use, kid and key_ops do not affect the PEM output.
Output options for private keys
A JWK containing d is private. By default you get both the PKCS#8 private key and the derived public key. Choose Public key only to extract a shareable public key from a private JWK, or Private key only to get just the PKCS#8 block. Public JWKs always produce a public PEM.
Common errors and fixes
- "Symmetric oct keys have no PEM form": an HMAC key is just bytes. The secret is the Base64URL value in
k, so decode it with a Base64 tool instead. - "Each key needs a kty member": you pasted something other than a JWK, such as an OpenID configuration document. Open its
jwks_uriand paste that JSON instead. - "Input must be a JWK or JWKS JSON object": the JSON is invalid. Check for trailing commas or a truncated copy.
For the reverse conversion use PEM to JWK. To verify a token directly against a JWKS without converting, paste it into the JWT verifier.
Privacy
Keys are converted with the jose library in your browser and are never uploaded.