Skip to content

PEM to JWK converter

Turn a PEM public key, private key or certificate into a JSON Web Key, with a kid, alg and use of your choice.

Runs in your browser. Nothing you paste is sent to us.

PEM

Reads BEGIN PUBLIC KEY, RSA PUBLIC KEY, CERTIFICATE, PRIVATE KEY, RSA PRIVATE KEY and EC PRIVATE KEY. A sample RSA public key is filled in.

JWK

JWK
 

How to use it

  1. Paste the PEM block: a public key, an RSA or EC private key, or a certificate.
  2. Choose the kid: the RFC 7638 thumbprint, your own, or none.
  3. Pick the algorithm and use the key is meant for.
  4. Copy the JWK, or the ready-made JWKS with only the public key.

What to know

The tool reads SPKI, PKCS #1, PKCS #8, SEC 1 EC keys and X.509 certificates. From a certificate it takes the public key and puts the certificate in x5c.

If you paste a private key, you also get the public JWK alone. Publish only that one.

Encrypted private keys and OpenSSH keys are not read. Convert them to plain PEM first with openssl or ssh-keygen.

Why turn a PEM key into a JWK

Keys are usually created with tools that write PEM: OpenSSL, ssh-keygen in PEM mode, cloud key services, certificate authorities. OAuth and OpenID Connect, on the other hand, exchange keys as JSON Web Keys.

You need the JWK form when you publish a key set for your own service, register a client’s public key with an authorization server, or configure a library that reads JWKs. This tool reads the common PEM forms and writes the matching JWK, with a key id and the metadata you choose.

The PEM forms it reads

The label on the BEGIN line tells you what is inside the Base64.

PEM labelContentsStandard
PUBLIC KEYAny public key with its algorithmSPKI (RFC 5280)
RSA PUBLIC KEYAn RSA public key onlyPKCS #1 (RFC 8017)
CERTIFICATEAn X.509 certificate with a public key insideRFC 5280
PRIVATE KEYAny private key with its algorithmPKCS #8 (RFC 5208)
RSA PRIVATE KEYAn RSA private key onlyPKCS #1
EC PRIVATE KEYAn EC private key with its curveSEC 1 (RFC 5915)

Keys protected with a passphrase (ENCRYPTED PRIVATE KEY) and OpenSSH keys (OPENSSH PRIVATE KEY) are not read. Convert them to plain PEM first with openssl pkcs8 or ssh-keygen -p -m PEM.

How the conversion works

The tool decodes the Base64 body into DER bytes and reads the ASN.1 structure. Older RSA and EC forms are rewrapped into SPKI or PKCS #8, and a certificate gives up its SPKI. Then Web Crypto imports the key and exports it as a JWK, which checks that the key is valid on the way.

Only the key material is kept: n and e for RSA, crv, x and y for EC, and the private members when the input is a private key. You then add the metadata.

An EC public key as a JWK, with a thumbprint kid (sample)
{
  "kty": "EC",
  "kid": "F53etudom86_iDj_5yR-Z9hsuTXdSuYhTtAKVu4i2Y8",
  "use": "sig",
  "alg": "ES256",
  "crv": "P-256",
  "x": "…",
  "y": "…"
}

Choosing kid, alg and use

Key id

The kid lets a verifier pick this key out of a set. Any string unique in the set works. The default here is the RFC 7638 thumbprint: a SHA-256 hash of the key’s required members, so the same key always gets the same id. You can type your own, or leave it out.

Algorithm

The alg member ties the key to one algorithm, which protects against a verifier using it in an unexpected way. RSA keys can serve RS256, PS256 and others, or RSA-OAEP for encryption. EC keys follow their curve: P-256 for ES256, P-384 for ES384, P-521 for ES512.

Use

Set use to sig for signing keys and enc for encryption keys. Using one key for both is discouraged; keep two.

How to convert a key

  1. Paste the PEM block, including the BEGIN and END lines.
  2. Check the summary: what was found, the key type and the size.
  3. Choose the kid: thumbprint, your own, or none.
  4. Choose the algorithm and use.
  5. Copy the JWK, or the JWKS that contains only the public key.

Using the result with Keycloak

Clients that sign their own JWTs

A Keycloak client can authenticate with “Signed JWT” (private_key_jwt). Keycloak then needs the client’s public key. On the client’s Keys tab you can import a certificate or turn on “Use JWKS URL” and give the address where your app publishes its key set. This tool produces that key set from your PEM key.

Identity provider federation

When Keycloak brokers another OpenID Connect provider, it validates that provider’s tokens with keys from its JWKS URL or with a key you enter. Converting the provider’s PEM key to JWK helps you compare it with what the provider publishes.

Your own services

If one of your services issues tokens, it should publish a JWKS like Keycloak’s certs endpoint. Paste its public key here to get the JSON.

Certificates and x5c

When you paste a certificate, the JWK gets an x5c member holding the certificate in standard Base64, and the summary shows the subject and expiry. Some clients use x5c to check a key against a trusted certificate authority; most just use the key.

To read the rest of a certificate, such as its issuer, serial number and extensions, use the X.509 decoder.

Common errors

  • “No PEM block found”: the BEGIN or END line is missing or damaged, often from copying only the Base64 body.
  • “Only RSA, EC and Ed25519 keys are supported”: DSA and other key types cannot become JWKs here.
  • “Only the P-256, P-384 and P-521 curves”: curves such as secp256k1 are not supported by Web Crypto.
  • “This private key is encrypted”: remove the passphrase locally first.
  • “This EC private key does not name its curve”: rare SEC 1 keys omit the curve; export the key again with its parameters.

Publishing a key set for your own client

When a client authenticates to Keycloak with a signed JWT, Keycloak can fetch the client’s public keys from a URL. Here is a simple way to set that up.

  1. Generate a key pair and keep the private key in your app’s secret store.
  2. Paste the public key here, keep the thumbprint kid, set alg to the algorithm your app signs with, and use to sig.
  3. Serve the “As a JWKS” output at a stable HTTPS address, such as /.well-known/jwks.json on your app.
  4. In Keycloak, open the client, then the Keys tab, turn on “Use JWKS URL” and enter that address.
  5. Sign the client assertion with the private key and put the same kid in its header.

To rotate later, add the new public key to the served set first, switch your app to the new private key, then remove the old key from the set.

Checking the result

Before you rely on a converted key, confirm it is the one you think it is.

  • Compare the size in the summary with the key you generated: 2048 bits, P-256, and so on.
  • Paste the JWKS into the JWKS viewer to see the thumbprint and any warnings.
  • Sign a test token with the private key and verify it with the JWK in the signature verifier.

Keep the PEM file and the JWK side by side in your notes during the first rollout, labelled with the kid. It makes the next rotation much easier to reason about.

Security notes

Converting a public key or certificate is harmless. With a private key, the tool shows a private JWK and, separately, the public JWK that is safe to publish. Only the public one belongs in a JWKS.

Nothing you paste leaves your browser. Still, treat a private key you pasted into any web page as something to handle carefully, and prefer local tools for production keys.

Best practices

  • Publish only public keys, and only over HTTPS.
  • Set kid, use and alg on every published key.
  • Use the thumbprint as kid when you have no naming scheme of your own.
  • Keep the previous key in your published set until tokens signed with it have expired.
Questions

Frequently asked questions

Which kid should I use?

Any string that is unique in your key set works. The RFC 7638 thumbprint is a good default because it is derived from the key itself and never collides by accident.

Does the JWK include the private key?

Only if you pasted a private key. The tool then shows the private JWK and, separately, the public JWK that is safe to share.

Can I convert a certificate to a JWK?

Yes. The public key inside the certificate becomes the JWK, and the certificate itself goes into `x5c`.

Why is my private key rejected?

It may be encrypted with a passphrase, or in OpenSSH format. Convert it to an unencrypted PEM private key with OpenSSL or ssh-keygen first, on your own machine.

How do I give Keycloak my client’s public key?

On the client’s Keys tab, either import a certificate or turn on “Use JWKS URL” and point it to a key set your app publishes. This tool can produce that key set from a PEM key.

What is the difference between SPKI and PKCS #1?

SPKI (`BEGIN PUBLIC KEY`) names the algorithm and works for any key type. PKCS #1 (`BEGIN RSA PUBLIC KEY`) holds only RSA keys. Both convert to the same JWK.

Is the key sent to a server?

No. Parsing and conversion run in your browser with Web Crypto.

Why does the JWK not include `key_ops` or `ext`?

Those members come from Web Crypto’s export and describe browser permissions, not the key. The tool removes them and keeps only the key material plus the `kid`, `alg` and `use` you choose.

Can I convert a key set from several PEM files at once?

Convert each key here, then put their public JWKs together in one `keys` array. Give each a unique `kid`, which the thumbprint option does for you.

Why does the size show 2048 bits for my RSA key?

The size is the length of the RSA modulus, `n`, in bits. Keys made with `openssl genrsa 2048` or similar commands show 2048.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.