Skip to content

JWT Nested Tokens — Signing and Encrypting Tokens with JWS and JWE

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about JWT Nested Tokens. We cover key concepts, practical examples, and best practices to help you master this topic.

JWT nested tokens apply both signing (JWS) and encryption (JWE) to the same payload, providing integrity verification and confidentiality for sensitive claims like PII, financial data, or authorization details.

What You'll Learn

  • JWS + JWE nesting patterns
  • Sign-then-encrypt vs encrypt-then-sign
  • Nested token structure and Serialization
  • Performance considerations of nesting
  • When to use nested vs signed-only tokens

Real-World Use

A healthcare API uses nested JWTs for patient data access. The inner JWS carries patient ID, diagnosis codes, and practitioner authorization with an ES256 signature. The outer JWE encrypts the entire signed token with RSA-OAEP. Even if intercepted, the patient data remains confidential and tamper-proof.

flowchart LR
    A["Claims: {patient_id, diagnosis, roles}"] --> B["JWS Sign with ES256"]
    B --> C["JWS Token (readable)"]
    C --> D["JWE Encrypt with RSA-OAEP + A256GCM"]
    D --> E["Nested JWT (opaque)"]
    E --> F["Transmit over network"]
    F --> G["JWE Decrypt"]
    G --> H["JWS Verify"]
    H --> I["Claims extracted"]

What's Next

Explore {{< ilink "JWT" "JWT JOSE" }} for the JWS/JWE standards, and review {{< ilink "JWT" "JWT Best Practices" }} for production token security.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro