What an encrypted JWT is
Most JWTs are signed: anyone can read them, but nobody can change them. An encrypted JWT uses JSON Web Encryption (JWE, RFC 7516) instead, so only the intended recipient can read the content. You use it when a token carries data that the parties in between should not see.
You can recognize a JWE in compact form by its five parts separated by dots, where a signed token has three. Only the first part, the protected header, can be read without the key.
Encryption also changes what intermediaries can do. A gateway that routes requests by reading claims cannot read an encrypted token, so routing must rely on other information, or the gateway must hold the decryption key itself.
The five parts
| Part | Contents | Readable? |
|---|---|---|
| 1. Protected header | JSON naming alg, enc, kid and more | Yes |
| 2. Encrypted key | The content key, encrypted for the recipient | No |
| 3. Initialization vector | Random bytes for the content cipher | Bytes only |
| 4. Ciphertext | The encrypted content | No |
| 5. Authentication tag | Proves the ciphertext and header were not changed | Bytes only |
All five are Base64url-encoded. The protected header is also the additional authenticated data for the content cipher, so changing the header breaks decryption.
alg and enc: two layers
A JWE uses two algorithms. alg says how the content key reaches the recipient. enc says how the content is encrypted with that key.
Key management (alg)
| alg | How the key is delivered | Encrypted key part |
|---|---|---|
RSA-OAEP, RSA-OAEP-256 | Encrypted to the recipient’s RSA public key | As long as the RSA modulus |
RSA1_5 | RSA PKCS #1 v1.5, deprecated in practice | As long as the RSA modulus |
ECDH-ES | Derived from an ephemeral EC key and the recipient’s key | Empty |
ECDH-ES+A128KW and similar | Derived key wraps a random content key | Present |
A128KW, A256KW | Wrapped with a shared AES key | Present |
dir | The shared key is the content key | Empty |
Content encryption (enc)
| enc | Cipher | IV | Tag |
|---|---|---|---|
A128GCM, A192GCM, A256GCM | AES-GCM | 12 bytes | 16 bytes |
A128CBC-HS256 | AES-128-CBC with HMAC SHA-256 | 16 bytes | 16 bytes |
A192CBC-HS384 | AES-192-CBC with HMAC SHA-384 | 16 bytes | 24 bytes |
A256CBC-HS512 | AES-256-CBC with HMAC SHA-512 | 16 bytes | 32 bytes |
What this inspector does
- Decodes and shows the protected header.
- Explains
alg,enc,kid,ctyandepkin words. - Measures each part in bytes.
- Checks the IV and tag sizes against what
encrequires. - Checks that the encrypted key part is empty or present as
algrequires. - Reads the recipient’s RSA key size from the encrypted key length.
- Warns about
RSA1_5and notes compression (zip).
It does not decrypt. Decryption needs the recipient’s private key or the shared key, and this page never asks for either.
{
"alg": "RSA-OAEP",
"enc": "A256GCM",
"kid": "sample-acme-enc",
"cty": "JWT"
}How to inspect a token
- Paste the token in compact form: five parts joined by dots.
- Read the badges for
alg,enc,kidandcty. - Read the explanations next to each header field.
- Check the size checks; a failed one means the token was damaged or built wrongly.
If you paste a three-part token, the tool tells you it is a signed JWT and points you to the JWT decoder.
Nested tokens: signed, then encrypted
Encryption alone does not prove who sent a token: anyone with the recipient’s public key can encrypt. So the usual pattern is to sign first and encrypt the signed token. The header then says cty: JWT, and after decrypting, the recipient must still verify the inner token’s signature.
Encrypted tokens in Keycloak
Keycloak can encrypt the ID tokens it issues to a client. In the client’s Advanced tab, the fine-grained OpenID Connect settings include an ID token encryption key management algorithm and a content encryption algorithm. Keycloak encrypts to a public key the client provides, such as through the client’s JWKS URL on its Keys tab.
Keycloak also has its own encryption key in each realm, listed with use: enc and alg: RSA-OAEP in the realm’s certs endpoint. Clients use it to encrypt things sent to Keycloak, such as request objects, when that is configured.
Access tokens from Keycloak are signed JWTs by default. If you see five parts, check which token you copied and which client settings apply.
Use cases
Debugging a decryption failure
Check that kid names a key the recipient has, that the recipient supports alg and enc, and that the part sizes pass. A size failure points to a damaged token or a buggy encoder.
Confirming a client setting
After turning on ID token encryption, inspect a token to confirm the algorithms are the ones you chose and the kid is the client’s current key.
Reviewing a partner’s tokens
The header shows whether a partner uses current algorithms. RSA1_5 or compression are worth raising.
How decryption works, step by step
Knowing the steps a recipient follows helps you read the header and the part sizes.
- Read the protected header to learn
alg,encandkid. - Find the private key or shared key named by
kid. - Recover the content key: decrypt the encrypted key with RSA-OAEP, unwrap it with AES key wrap, or derive it with ECDH-ES, as
algsays. - Decrypt the ciphertext with the content key and the IV, using the protected header as additional authenticated data.
- Check the authentication tag. If it does not match, reject the token: something was changed.
- If
ctyisJWT, verify the inner signed token.
Every step can fail on its own, which is why decryption errors are often vague. The header and the part sizes rule out half of the causes before you need the key.
Reading the sample
The sample token on this page is made up for the realm acme. Its header names RSA-OAEP and A256GCM.
- The encrypted key is 256 bytes, so the recipient’s RSA key is 2048 bits.
- The IV is 12 bytes and the tag 16 bytes, as AES-GCM requires.
- The ciphertext is about the size of the signed token inside it, since GCM adds no padding.
cty: JWTsays the content is a token to verify after decrypting.
Nobody can decrypt it: the private key was discarded when the sample was made.
JWE in JSON serialization
RFC 7516 also defines a JSON form, with members such as protected, encrypted_key, iv, ciphertext and tag, and optionally several recipients. It is rare in OAuth and OpenID Connect, which use the compact form. This tool reads the compact form only and tells you when you paste JSON.
Security notes
RSA1_5has a long history of padding-oracle attacks. PreferRSA-OAEPorRSA-OAEP-256.- Compression (
zip: DEF) before encryption can leak information about the content through its length when an attacker controls part of it. - The header is not secret. Do not put sensitive data in custom header fields.
- Decrypting does not authenticate the sender; verify the inner signature.
When a recipient cannot decrypt, start from the header: confirm the kid exists in the recipient’s key set with use: enc, that the recipient supports both alg and enc, and that the part sizes pass. Only then look at the key itself.
Best practices
- Sign, then encrypt, and mark the content with
cty: JWT. - Use RSA-OAEP-256 or ECDH-ES for key management and AES-GCM for content.
- Give encryption keys their own
kidanduse: enc, separate from signing keys. - Use encryption only where intermediaries must not read the claims; it adds cost and complexity.