opyeb JWTScope

Guides · Keys and flows

JWE: when a token must be unreadable, not just signed

Updated 28 Nov 2026 · 6 min read

A JWS protects integrity: it proves who wrote the claims and that they were not changed. It does not hide them. Base64url is reversible with no key, so a signed token in a log, a browser history or an email is readable by anyone who sees it. When confidentiality is required, JOSE provides JSON Web Encryption, JWE, defined in RFC 7516.

A JWE encrypts arbitrary bytes, which may be a JSON claims set or an entire signed JWT. It uses two layers of cryptography: a key management algorithm that establishes a content encryption key for the recipient, and a content encryption algorithm that encrypts the payload and authenticates it. The result is a compact string with five segments rather than three.

SegmentNameContent
1Protected headerbase64url JSON with alg, enc, kid and other parameters
2Encrypted keyThe content encryption key, wrapped for the recipient
3Initialization vectorNonce for the content cipher
4CiphertextThe encrypted payload
5Authentication tagIntegrity tag over header, IV and ciphertext

Key management and content encryption

The protected header names two algorithms. alg is the key management algorithm, such as RSA-OAEP, ECDH-ES or A256KW, which determines how the content encryption key is delivered. enc is the content encryption algorithm, such as A256GCM or A128CBC-HS256, which determines how the payload is encrypted and authenticated. A header without both is incomplete.

The authentication tag is what makes JWE more than encryption. It covers the protected header, the initialization vector and the ciphertext, so an attacker cannot change the header, for example to swap the key management algorithm, without the tag failing. A recipient must verify the tag before using any plaintext, and must reject a token whose header algorithms are not in its allowlist.

What encryption does and does not hide

JWE hides the payload from anyone without the decryption key, including the client that holds the token if the key is not shared with it. It does not hide the fact that a token exists, its size, or the protected header, which is only base64url. The header can reveal the issuer, the key ID and the algorithms even when the claims are hidden. If metadata matters, it needs the same care as the payload.

Encryption also does not make a token trustworthy on its own. A JWE can be created by anyone who has the recipient's public key, so the recipient learns confidentiality but not authenticity. That is why sign-then-encrypt exists: the inner signature proves the issuer, the outer encryption hides the content. Decrypt-then-verify is the correct order, and the inner token's audience and time claims still have to be checked.

Nested JWTs in practice

A nested JWT has a JWS as the payload of a JWE, or occasionally the reverse. The outer cty header is set to JWT to say that the plaintext is itself a JWT. The recipient decrypts, checks that the inner token is a JWS, verifies it with the issuer's key, and only then reads claims. Each layer has its own algorithm and key, and both must be validated.

Nesting adds size and operational complexity. A 2048-bit RSA-encrypted token with an RSA-signed inner token can exceed 2 KB before any claims. Many systems avoid JWE by keeping sensitive data out of tokens entirely: the token carries an opaque identifier, and the service fetches the details over an authenticated channel. That is often simpler and easier to revoke than encrypting a large claims set into every request.

Why this verifier stops at the header

Decrypting a JWE requires a private key or a shared secret. A web page that asks visitors to paste a private key is asking them to move a high-value secret into a browser context, where an extension, a compromised dependency or a future change to the page could read it. This tool does not do that. It identifies a five-part token, decodes the protected header, and explains what would be needed to decrypt it.

If you need to decrypt for debugging, use a local command-line tool with a test key, never a production private key, and keep the key out of shell history and logs. The same rule as everywhere else: a key that has been pasted into a chat window or a web form should be considered exposed and rotated.

Choosing JWE or a different design

JWE is a well-specified tool with good library support, but it is not a default. Most access-token problems are solved by short lifetimes, narrow scopes and keeping personal data out of the token. Encryption is for the cases where the payload itself must remain confidential, and it should be chosen deliberately, with the key management and the verification order written down.

Signed means tamper-evident. Encrypted means unreadable. Neither means a token is safe to log, and neither replaces validating the issuer, audience and time.

Sources

Questions

Is a signed JWT private?

No. The payload is base64url, not encryption. Anyone with the token can read every claim. If the claims contain personal data that must not be visible to the holder or to intermediaries, the token needs JWE encryption or the data must stay out of the token.

Can a token be both signed and encrypted?

Yes. The usual pattern is sign-then-encrypt: a JWS is the plaintext of a JWE. The recipient decrypts, then verifies the inner JWS. This gives authenticity and confidentiality, at the cost of size and complexity. Nested JWT is the term for a JWT inside a JWT.

Why does this site not decrypt JWE?

Because decryption needs a private key, and asking visitors to paste one into a web page is a risk this tool will not take. The verifier identifies a JWE, shows its protected header and explains the segments, but leaves decryption to a local library.

Paste a five-part token into the verifier and it will tell you it is a JWE rather than pretending to verify it.

Open the verifier

Written against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.

Back to the guides