JWS: verify signed data and distinguish it from encryption
Understand what JWS protects, how its compact form is structured, what signature verification proves, and what still requires separate checks.
JWS: verify signed data and distinguish it from encryption
JSON Web Signature (JWS) is a format for protecting arbitrary data with a digital signature or a MAC (message authentication code based on a shared secret). A receiver can verify the signature with a trusted key to check that the protected content has not changed and that it was produced by a party holding the corresponding key. JWS does not hide its payload. If confidentiality is required, use a separate design such as JSON Web Encryption (JWE).
The three parts of Compact JWS
The commonly seen Compact Serialization joins three parts with periods:
base64url(protected header).base64url(payload).base64url(signature)**Protected header:** identifies the signature method and parameters, such as `alg`. In Compact form, the entire protected header is included in the signature input.
**Payload:** the bytes being protected. A JWT payload usually contains JSON claims. Base64url is an encoding, not encryption.
**Signature:** the signature or MAC calculated over the protected header and payload. If either changes, verification fails.
JWS also has a JSON Serialization that can represent the same payload with multiple signatures or MACs. Compact form is concise and URL-safe; JSON Serialization can be useful when multiple signatures must be represented.
What verification does and does not establish
A valid signature helps establish integrity and that the data was signed by a party associated with the key. It does not by itself make the data safe or authorize its use for the current request. The receiver must use a key from a trusted issuer. For a JWT, it must separately validate issuer, audience, expiry, token type, and application permissions. Accepting unsigned data or arbitrary algorithms defeats JWS protection.
The key type also matters. With an asymmetric digital signature, the private-key holder signs and recipients can verify with the public key. With a MAC, every party holding the same secret can create or verify the value. Consider this trust boundary when distributing keys among verification services.
Relationship between JWT and JWS
A JWT represents JSON claims; a common signed JWT is carried as a JWS. But a JWS payload is not always a JWT: JWS can protect arbitrary bytes. Seeing a JWS structure also does not prove that it is an OAuth access token. An API must first identify the expected profile and then enforce its required headers and claims.
A safe processing sequence
Confirm that the input uses the expected JWS serialization: Compact or JSON, and whether a detached payload is part of the contract.
Restrict algorithms to a preconfigured allowlist. Do not let the header’s `alg` define policy, and ensure the selected key is compatible.
Obtain keys from trusted issuer metadata or another verified distribution channel. Header `kid` is a selection hint, not evidence that the key is trustworthy.
Verify with a standard library. Decoding the payload alone is not verification. Reject unsupported algorithms, invalid signatures, and unexpected keys.
After signature verification, check the application’s required claims and permissions. Do not log the raw token or sensitive payload.
Common misunderstandings
**“I can read the decoded three parts, so they are encrypted.”** Base64url encodes data; it does not conceal it.
**“A valid signature means this API can use the token.”** Signature validation does not replace issuer, audience, expiry, or permission checks.
**“The `kid` proves this is the real key.”** It is an identifier used to find a key in a trusted set. Authenticate the source first.
**“JWS always means a digital signature.”** JWS can represent a digital signature or a MAC; who can create values depends on the algorithm and key.
**“JWS and JWE provide the same protection.”** JWS provides integrity/authenticity checks; JWE provides confidentiality through encryption. A protocol must define whether one or nested forms are required.
References
[RFC 7515 — JSON Web Signature (JWS)](https://www.rfc-editor.org/rfc/rfc7515.html)
[RFC 7519 — JSON Web Token (JWT)](https://www.rfc-editor.org/rfc/rfc7519.html)
[RFC 7516 — JSON Web Encryption (JWE)](https://www.rfc-editor.org/rfc/rfc7516.html)
[RFC 9068 — JWT Profile for OAuth 2.0 Access Tokens](https://www.rfc-editor.org/rfc/rfc9068.html)