Cryptography

JWK to PEM Converter

Convert JWK public keys to PEM format in your browser. Supports RSA and EC keys, outputs PEM SPKI blocks ready for OpenSSL, curl, and JWKS workflows.

Backend developers, DevOps engineers, and security integrators encounter JWK format whenever they work with OIDC providers, JWKS endpoints, or JWT verification. Most command-line and library tooling still expects PEM, so conversion is a routine but error-prone step. When to use it: Verifying a token with OpenSSL, feeding a public key to curl for mutual TLS, loading a JWKS key into a Java or Python service, or debugging why a key file is rejected by a tool. What it solves: Validates required fields for RSA and EC keys, decodes base64url parameters, assembles a correct DER SubjectPublicKeyInfo structure with the right algorithm identifiers, and wraps it in standard PEM encoding. Why it matters: Hand-rolling this conversion in shell scripts or ad-hoc code frequently produces keys with wrong algorithm identifiers or malformed DER, causing cryptic errors downstream. A dedicated converter with validation catches those mistakes immediately.

Paste a single JWK object. For a JWKS set, extract the specific key you need first.

How JWK to PEM Conversion Works

The converter parses the pasted JSON and identifies the key type from the kty field. For RSA keys it expects the modulus (n) and exponent (e). For EC keys it expects the curve name (crv) and the x and y coordinates.

Each base64url-encoded field is decoded to raw bytes. The algorithm identifier is assembled — the RSA OID with a NULL parameter, or the EC OID paired with the curve-specific OID. These identifiers are what tell the consuming tool which algorithm the key supports.

DER assembly constructs the SubjectPublicKeyInfo structure: an outer sequence containing the algorithm identifier and a bit string wrapping the raw key material. For RSA this is a sequence of modulus and exponent; for EC it is an uncompressed point prefix followed by the x and y coordinates.

PEM wrapping base64-encodes the DER bytes and breaks them into 64-character lines between the BEGIN and END PUBLIC KEY markers. The result is a standard PEM file content that OpenSSL and friends can read directly.

Before / After Examples

Example 1: RSA JWK to PEM

❌ Before (JWK JSON)

{
  "kty": "RSA",
  "kid": "my-key-1",
  "n": "0vx7agoebGcQSuuPiLJX...",
  "e": "AQAB"
}

<!-- Not usable with OpenSSL -->

✅ After (PEM SPKI)

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEA0vx7agoebGcQSuuPiLJX...
[...]
-----END PUBLIC KEY-----

<!-- Ready for OpenSSL and curl -->

Example 2: EC P-256 JWK to PEM

❌ Before (EC JWK)

{
  "kty": "EC",
  "crv": "P-256",
  "x": "f83OJ3D2xF1Bg8vub9tL...",
  "y": "x_FEzRu9m36HLN_tue65..."
}

<!-- Raw coordinates, no structure -->

✅ After (EC PEM with curve OID)

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0D
AQcDQgAEf83OJ3D2xF1Bg8vub9tL...
[...]
-----END PUBLIC KEY-----

<!-- Algorithm + curve identifiers embedded -->

Example 3: Feeding the PEM to OpenSSL

❌ Before (JWK passed directly)

$ openssl pkey -in jwk.json
openssl: unable to load key
<!-- OpenSSL does not read JWK -->

✅ After (PEM file works)

$ openssl pkey -in key.pem -pubin -text
RSA Public-Key: (2048 bit)
Modulus: 00:ad:ff:0b:...
[...]
<!-- Parses cleanly -->

Use Cases

Developer Production Workflow
Convert JWKS keys for local JWT verification Load OIDC provider keys into a Java service Debug token verification failures in staging
Test key formats with OpenSSL locally Configure mutual TLS with JWK-sourced certs Validate key rotation before deploying to prod
Feed converted keys into Python cryptography libs Audit JWKS endpoint key material Document key conversion steps for team runbooks
Verify EC curve identifiers in a crypto library Standardize PEM key files across services Security review of key handling pipeline

Common Mistakes & Troubleshooting

Pasting the entire JWKS set

A JWKS response contains a keys array with multiple JWK objects. This tool expects a single JWK. Extract the specific key you need — usually the one with use: sig and the current kid — before pasting.

❌ { "keys": [ { ... }, { ... } ] }
✅ { "kty": "RSA", "n": "...", "e": "AQAB" }

Using a private JWK expecting a private PEM

This converter produces public keys only. If the JWK contains a private parameter (d for RSA or EC), it is ignored. You need a separate private key conversion tool for signing operations.

❌ Expecting private PEM from a public key conversion
✅ Public JWK → public PEM (for verification only)

Wrong algorithm identifier in hand-built DER

Manually assembling DER often uses the wrong OID or omits the NULL parameter for RSA. Tools then reject the key or silently misinterpret the algorithm. Let the converter handle algorithm identifiers.

❌ Manual DER with missing NULL after RSA OID
✅ Converter embeds correct OID + parameters

Feeding base64 (not base64url) into JWK fields

JWK fields use base64url encoding — with - and _ instead of + and /, and no padding. If you have standard base64 from another source, convert it first or the decoder will reject it.

❌ "n": "abc+def/ghi="  (standard base64)
✅ "n": "abc-def_ghi"    (base64url, no padding)

Expecting Ed25519/OKP support

Octet key pairs (kty: OKP) used for Ed25519 are not supported because their PEM representation varies across tools. Extract the raw key and use a dedicated Ed25519 conversion utility instead.

❌ { "kty": "OKP", "crv": "Ed25519", ... }  (unsupported)
✅ { "kty": "RSA" } or { "kty": "EC" }  (supported)

Best Practices

✓

Extract one key at a time from JWKS

JWKS sets contain multiple keys. Identify the specific key by kid or use before converting to avoid ambiguity.

✓

Verify fingerprints after conversion

Compare the DER fingerprint before and after conversion against your source tool's output to confirm the key material is unchanged.

✓

Keep PEM files out of version control

Even public keys in PEM form are better managed with secrets tooling than committed to a repository. Store them in your deployment configuration.

✓

Use offline tools for key material

Public keys are not secret, but in sensitive environments use offline converters like this one to keep all key handling within your network.

✓

Match key type to the consuming tool

Some tools only accept RSA, others prefer EC. Check the requirements of your target library before choosing which JWKS key to extract.

✓

Handle key rotation explicitly

When your identity provider rotates keys, re-fetch the JWKS and re-convert. Hard-coded PEM files go stale and cause verification failures.

✓

Test with openssl before deploying

Run openssl pkey -in key.pem -pubin -text on the output to confirm it parses. This catches malformed DER before it reaches production.

✓

Never convert private keys with public tools

Private key material requires dedicated, audited conversion tools. This converter is for public keys only — keep private JWKs out of browser-based tools.

Frequently Asked Questions

What is a JWK and when do I need to convert it? +

A JWK (JSON Web Key) is a JSON representation of a cryptographic key, defined in RFC 7517. JWKS endpoints publish JWK-formatted public keys so services can verify tokens without exchanging key files manually. You need to convert JWK to PEM when a tool expects traditional key files — OpenSSL, curl with client certificates, many Java and Python libraries, and most SSH tooling. The conversion is a format change only; the key material is identical.

What is the difference between JWK and JWKS? +

JWK is a single key in JSON format. JWKS (JSON Web Key Set) is a JSON object containing a set of JWKs, typically published at a well-known URL like /.well-known/jwks.json. When you fetch a JWKS endpoint, you get multiple keys — often one current and one previous for rotation. This tool converts one JWK at a time, so extract the specific key you need from the set first.

What does PEM format mean? +

PEM is a text encoding for binary key and certificate data, recognizable by the -----BEGIN ...----- and -----END ...----- header and footer lines. Inside, the base64 content is DER (Distinguished Encoding Rules) — the actual binary structure of the key. Public keys in PEM typically use the PUBLIC KEY label, which wraps the key in a SubjectPublicKeyInfo structure. This is the format OpenSSL, curl, and most command-line tools expect.

Does converting JWK to PEM change the key? +

No. Conversion only changes the encoding from JSON to PEM/DER. The mathematical key material — the modulus and exponent for RSA, or the curve and coordinates for EC — is byte-for-byte identical. You can verify this by comparing fingerprints before and after conversion, or by loading both formats into OpenSSL and confirming they produce the same output. The tool displays a fingerprint of the DER structure so you can confirm consistency.

Which key types does this converter support? +

It supports RSA keys (kty: RSA, using the n and e fields) and EC keys (kty: EC, using crv, x, and y fields) with curves P-256, P-384, and P-521. These cover the vast majority of keys found in JWKS endpoints. Octet key pairs (kty: OKP) used for Ed25519 are not supported because their PEM representation varies significantly across tools.

Why does the converted PEM not work with my private key operations? +

JWK public keys contain only the public portion of the key pair. PEM conversion of a public key produces a public key — it cannot sign or decrypt. If you need private key operations, you need the private JWK (which includes the d parameter for EC or d for RSA) and a tool that supports private key conversion. Never share private JWKs; they grant full control of the key.

How does this JWK to PEM converter work? +

You paste a JWK JSON object. The tool validates the required fields for the key type, decodes the base64url-encoded parameters, assembles a DER SubjectPublicKeyInfo structure using the correct algorithm identifiers, and wraps it in PEM encoding. Everything runs in your browser — the key never leaves your machine, which matters because JWKS keys are public but the conversion workflow should still be offline-capable for security-sensitive environments.