PEM to JWK Converter

Paste a public key in PEM form and get the same key back as a JWK. The key doesn't change, only the way it's written down.

FluffyShield Protected workspace
FluffyShield

Isolated workspace: other page scripts can't read your files. How FluffyShield works

Free · No upload · No sign-up · No usage quotas

Is the JWK really the same key as your PEM?

Yes, and you can check it by eye. Most of the JWK's x is sitting in your PEM, letter for letter.

What the converter does
  1. Take off the BEGIN and END lines
  2. Read the letters back into bytes
  3. Write the key's numbers out under names

What it does

EC keys

On P-256, P-384 or P-521. The bigger the curve, the longer x and y get.

RSA keys

Two numbers, written as n and e, under "kty": "RSA".

Ed25519 keys

A single x and no y, because this kind of public key is one number, not two.

Limits One public key per paste, up to 16 MiB.

Two ways to write down one key

Someone has asked you for a public key "as a JWK", and what you have is a file whose first line reads -----BEGIN PUBLIC KEY-----. Maybe a colleague made it, maybe a key generator did. Either way, the key is fine. The system on the other end just wants it written differently.

Think of a postal address. On an envelope it's a few lines in an order everybody knows. On a shop's checkout page the same address goes into labelled boxes: street, town, postcode. Nobody has moved house.

PEM is the envelope. The key is stored as bytes, and the bytes are spelled out in letters so they can be pasted, between a BEGIN line and an END line. Nothing in between tells a person which letters are which. JWK, short for JSON Web Key, is the form with boxes: a short piece of text in curly brackets, with every part of the key under its own name. It comes from the same set of standards as the signed tokens behind a lot of web logins, which is why the systems that check those tokens ask for keys this way.

Finding the JWK's x inside the PEM

Here's the sample key this page uses, in both forms, with the PEM's letters broken into short rows.

In the PEMIn the JWKMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE"kty": "EC""crv": "P-256"36 letters: what kind of keypjb6n9aG/YHFfu/eqoaiK3Kgr1ZUNVPljMjsSzFwc2pjb6n9aG_YHFfu_eqoaiK3Kgr1ZUNVPljMjsSzFwc2The next 42 letters: the start of "x"

One key, two forms

The tinted letters are the only ones that differ: the PEM has a / where the JWK has an _. The rest of the 42 are the same. How we checked

The first 36 letters don't belong to your key at all. They say what kind of key follows: an elliptic-curve key, on the curve called P-256. Every P-256 public key saved this way starts with the same 36. The JWK says it in words, as "kty": "EC" and "crv": "P-256".

Then comes the key itself, which is two large numbers, x and y. The next 42 letters of the PEM are the first 42 of the JWK's x. The 2 that differ are spelled differently on purpose. A JWK is meant to be able to travel inside web addresses, where a / already means something, so it uses _ in its place, and - for +.

After that the letters stop lining up. Each letter stands for part of a byte, and from the end of x the two forms happen to cut the bytes up in different places, so y is spelled one way in the PEM and another in the JWK. It's the same number in both.

Why the JWK has no kid, alg or use

A JWK can carry more than the key. kid gives it a name, alg says which signing method it's for, and use says whether it's for signatures or for encryption. The one you get here has none of them.

That's because a PEM file has nowhere to keep them. There's nothing to copy across, and the converter doesn't make anything up: an alg picked by guesswork could tell the system on the other end to expect the wrong kind of signature.

If the form you're filling in asks for a kid, the value comes from that system's own instructions. Add it as one more line inside the brackets, with a comma after the line before; the key's own lines stay exactly as they are.

Copying the JWK for the form that asked

There's nothing to set first. The box at the top of this page, FluffyBench's Certificate and public key inspector, already reads PEM and writes JWK.

  1. Paste your key into the Public key box, from the -----BEGIN line down to the -----END line.

  2. The JWK appears under Result as soon as the key is in. There's no button to press.

    The Result box holding the JWK of the sample key, four lines of kty, crv, x and y, with Copy and Download above it.
    The Result box holding the JWK of the sample key, four lines of kty, crv, x and y, with Copy and Download above it.
  3. Press Download to save it as public-key.jwk, or Copy to paste it straight into the form that asked for it.

What it turns away

A file that starts -----BEGIN PRIVATE KEY----- (or EC PRIVATE KEY, or RSA PRIVATE KEY) is the other half of the pair, the half that signs. The box answers it with the heading "That’s a private key" and this, and nothing else: "Private keys aren’t accepted. Paste only a certificate, a signing request or a public key, and keep the private key secret."

That refusal is the right way round. A public key exists to be handed out, so pasting it into a web page gives nothing away. A private key should never be pasted into any page, this one included.

A certificate, whose first line says CERTIFICATE, is read for the public key inside it. The JWK leaves out the certificate's names and dates. A signing request is refused: "Provide a public-key or certificate PEM block. PEM-to-JWK does not read requests or private keys." Its key is wrapped in a request for a certificate, and this page does not read requests.

Keys outside the three kinds above stop with a message too, and so do RSA keys saved with their own extra settings (RSA-PSS keys).

What you have is a certificate, and you want to see what's in it

Certificate and public key inspector

Its Certificate tab shows who the certificate names, who issued it and the dates it covers.

Later you'll need the key back as PEM

JWK to PEM Converter

It writes the JWK out as a PUBLIC KEY block again, the same letters as the file you started with.

The system wants a binary .der file instead

PEM to DER Converter

DER is the same bytes your PEM spells out, saved as a file of their own.

Search FluffyBench