03 / 05

Difference between signed and encrypted JWT?

Difficulty: 6/10
JWT signing, JWT encryption, confidentiality vs integrity

Signed JWTs (JWS) ensure integrity and authenticity but are readable by anyone, while encrypted JWTs (JWE) ensure confidentiality, making the payload unreadable without the decryption key.

A signed JWT (JSON Web Signature, JWS) uses a secret or private key to create a digital signature over the header and payload. This guarantees that the token has not been tampered with and that it came from the expected issuer. However, the payload is only Base64Url-encoded, not encrypted, so anyone can decode and read its contents. Signing is used when you need to verify authenticity and integrity but do not require confidentiality.

An encrypted JWT (JSON Web Encryption, JWE) encrypts the payload using a symmetric or asymmetric encryption algorithm. The result is a ciphertext that can only be decrypted by the intended recipient who possesses the appropriate decryption key. This ensures confidentiality, meaning even if an attacker intercepts the token, they cannot read the sensitive data inside. Encryption is used when the token carries sensitive information that must be hidden from unauthorized parties.

Signed vs Encrypted JWT - Example
Key Differences
  1. 1

    Purpose: Signing provides integrity and authenticity; encryption provides confidentiality.

  2. 2

    Readability: Signed JWTs are Base64Url-encoded and can be decoded by anyone; encrypted JWTs are unreadable without the decryption key.

  3. 3

    Algorithms: Signing uses algorithms like HS256, RS256, ES256; encryption uses algorithms like RSA-OAEP, A128GCM, A256KW.

  4. 4

    Use cases: Signing is used for access tokens, ID tokens where the payload is not sensitive; encryption is used when the token contains sensitive data like personal information or payment details.

  5. 5

    Combined: It is possible to sign an encrypted JWT or encrypt a signed JWT to get both properties (JWS nested in JWE or vice versa).

Scenario Questions

0-2 years experience

  1. 1You need to issue a JWT for a client that only needs to verify the user's identity. Would you sign it, encrypt it, or both? Explain what happens if you choose the wrong option.
  2. 2In a small microservice that reads a JWT from an Authorization header, what will happen if the token is encrypted but the service only verifies the signature?

2-5 years experience

  1. 1Our API started rejecting JWTs after we switched from signed-only tokens to encrypted ones. Walk me through how you would debug the issue and what differences in processing you’d look for.
  2. 2We have a single-page app that stores a JWT in local storage. Should we use a signed token, an encrypted token, or both? Discuss trade‑offs regarding security and performance.

5-8 years experience

  1. 1Design a token strategy for a multi‑service platform where some services need to read claims and others must not see any user data. How would you combine signed and encrypted JWTs, and what are the operational considerations?
  2. 2At scale we need to rotate keys for both signing and encryption without downtime. Explain how you would manage key rotation for signed vs encrypted JWTs and what pitfalls to avoid.

8+ years experience

  1. 1Our company is moving from a legacy system that uses signed JWTs for authentication to a new zero‑trust architecture that requires encrypted JWTs for data confidentiality. Outline the migration plan, including compatibility layers, security reviews, and impact on cross‑team contracts.
  2. 2When evaluating compliance (e.g., GDPR, PCI) for a global service, how does the choice between signed and encrypted JWTs affect data residency and audit requirements? What architectural decisions would you make to satisfy both security and regulatory constraints?

Follow-up Questions

  • What are the security implications if you only sign a token that contains sensitive data?
  • How does key rotation differ between JWS and JWE?
  • Can you describe a scenario where you’d use sign‑then‑encrypt versus encrypt‑then‑sign?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.