Overview

11 JSON Object Signing and Encryption (JOSE)

Modern systems exchange data across languages, teams, and organizations, so shared, well-specified formats are essential for secure interoperability. The JOSE family of standards provides exactly that for JSON-based signing and encryption. JSON Web Algorithms (JWA) standardizes names for cryptographic algorithms, while JSON Web Key (JWK) expresses secret, public, and private keys as JSON. On top of these, JSON Web Signature (JWS) secures content against tampering and proves authenticity, and JSON Web Encryption (JWE) protects confidentiality and integrity of arbitrary byte payloads. Understanding these formats not only simplifies implementation but also makes troubleshooting and cross-platform integration far easier.

JWS packages three elements—header, payload, and signature—into a compact, Base64URL-encoded, dot-separated string that is safe for HTTP headers and URLs. The header declares the signing algorithm via a JWA identifier (for example, HS256), the payload holds arbitrary data, and the signature is either a MAC or a digital signature, providing integrity and authenticity (not confidentiality). Libraries like Nimbus streamline creation and verification, as illustrated by the ACME refunds scenario where JWS replaces ad hoc file-plus-checksum exchanges with a single, self-describing artifact. A critical implementation pitfall is the alg:none vulnerability; developers must explicitly reject unsigned tokens to prevent signature bypass.

JWE extends the model to deliver confidentiality with authenticated encryption, typically using AES-GCM. Its compact form includes a header, an optional encrypted content-encryption key, the ciphertext, and an authentication tag (with an initialization vector conveyed alongside). Direct encryption (alg: dir) omits the encrypted key when parties already share it. With JOSE-aware libraries, encryption and decryption become straightforward and interoperable without bespoke metadata handling. In terms of goals, JWS provides integrity and authenticity, while JWE adds confidentiality; symmetric variants do not provide non-repudiation. Finally, JSON Web Token (JWT) is a constrained use of JWS or JWE where the payload must be a JSON object with standardizable claims, a format widely used in identity protocols but sometimes criticized for flexible options that can be misconfigured if care isn’t taken.

Relationship between the standards that are part of the JSON Object Signing and Encryption (JOSE) suite. JOSE enables interoperability between applications that want to exchange encrypted or signed data using the JSON data format. JOSE standards are used extensively by popular security protocols such as OpenID Connect for Single Sign On.
ACME Inc. staff approve refunds using the warehouse management application. Once a day the warehouse management application generates a refunds.json file. The payment service refunds customer credit cards for the amount specified in the refunds.json file.
The logical structure of a JSON Web Signature (JWS). A JSON metadata header describing the type of signature used. A payload that can be any type of data format not just JSON. Signature to use verify that the header and payload were not tampered with. A JWS payload is always readable to anyone who can access the JWS object.
Road from data to a JWS. A JSON Web Signature (JWS) object can be safely embedded in a URL or HTTP headers because it is represented a base64 URL string where each component is separated by a dot.
Parts of a JSON Web Encryption (JWE) object.
A JSON web token (JWT) can be a JWS object with the added restriction that the payload must be JSON object.
The collection of standards. JSON Web Token (JWT) builds on top of the JWE and JWS standards. JWT is the token format for the OpenID Connect standard.

Summary

  • JSON Object Signing and Encryption (JOSE) is suite of standards used to represent cryptographic algorithms, keys, signed content, and encrypted content as JSON objects.
  • JOSE is widely used with excellent support in many programming languages. However, it has come in some criticism due to unnecessary complexity in the standard that make it easy to misuse. Watch out for the JWS alg:none vulnerability in any application or library you are using.
  • JSON Web Signature (JWS) is an industry standard data format for signed data, it has JSON metadata header, a payload that can have any format, and a signature to validate the payload and header were not tampered with.
  • JWS support signatures with message authentication codes (MACs) which we covered in this chapter and digital signatures which we will cover in a future chapter.
  • JSON Web Encryption (JWE) is an industry standard data format for representing encrypted data in JSON. It supports AES and has a lot of implementations in different programming languages.
  • JSON Web Key (JWK) used to represent cryptographic keys as JSON objects.
  • JSON Web Algorithm (JWA) used to define the various algorithms used by JWS, JWE, and JWK.
  • Always consult with your Information Security team to make sure you are using corporate recommended configurations of common cryptographic algorithms.
  • The examples in this book are optimized for educational value, they take shortcuts to make the code fit on the page, and to emphasis the concepts. Don’t copy and paste the sample code blindly, you must make it production ready before you use it.

FAQ

What is JOSE and which standards does it include?JOSE (JavaScript Object Signing and Encryption) is a suite of four IETF standards that enable interoperable signing and encryption with JSON: 1) JWA (JSON Web Algorithms) defines standard algorithm identifiers; 2) JWK (JSON Web Key) represents keys as JSON; 3) JWS (JSON Web Signature) protects integrity and authenticity; 4) JWE (JSON Web Encryption) adds confidentiality plus integrity.
Why do we need standardized algorithm identifiers (JWA)?Standard names prevent ambiguity between systems built by different teams and ensure the right algorithms are selected during processing. Examples: HS256 (HMAC with SHA-256), A256GCM (AES-256 in GCM mode), ES384 (ECDSA with P-384 and SHA-384). JWA identifiers are registered with IANA for consistency.
What is a JSON Web Key (JWK) and why is it useful?JWK is a JSON-based format for representing cryptographic keys (secret, public, private). It supports complex key types and metadata and is easy to exchange across services and languages. The kid (Key ID) field uniquely identifies a key for selection and rotation.
How is a JWS structured and represented?A JWS has three parts: header (metadata like alg), payload (the data), and signature. In compact form it’s Base64URL-encoded and dot-separated as header.payload.signature, making it safe for HTTP headers and URLs. The payload is readable (not encrypted).
What security guarantees does a JWS provide (and what doesn’t it)?With HS256, JWS provides integrity (no tampering) and authenticity (trusted origin). It does not provide confidentiality. Non-repudiation requires public-key signatures, which are covered in the next chapter.
How do I create and verify a JWS in Java?Using Nimbus: build a JWSHeader with HS256, create a JWSObject with the payload, sign with MACSigner(secret), then serialize. To verify, parse the compact JWS and call verify with MACVerifier(secret). Don’t hardcode secrets in production; use secure key management.
What is the “alg: none” vulnerability and how do I avoid it?Setting alg to none disables signature validation, letting attackers alter payloads undetected if the library accepts it. Mitigate by configuring your JWS/JWT library to reject alg: none. Nimbus’s MACVerifier throws on alg: none by default.
What is a JWE and what are its components?JWE encrypts content to provide confidentiality (and integrity). Conceptually it has: header, optional encrypted key (CEK), ciphertext (payload), and authentication tag. In compact form, the dot-separated parts include the header, encrypted key (may be empty), initialization vector (IV), ciphertext, and authentication tag, all Base64URL-encoded.
Why is the encrypted key empty in the example JWE?The example uses alg: dir (direct encryption), meaning sender and recipient already share the content encryption key, so no separate encrypted key is included.
How is a JWT related to JWS and JWE, and what’s the payload restriction?A JWT is either a JWS or a JWE with the additional requirement that its payload must be a JSON object. JWTs may include standard claims such as sub (the subject/user ID).

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Software Security for Developers ebook for free