Skip to main content

Appendix A. JWS Examples

Appendix A. JWS Examples

This appendix provides several examples of JWSs. While the first three examples all represent JSON Web Tokens (JWTs) [JWT], the payload can be any octet sequence, as shown in Appendix A.4.

A.1 Example JWS Using HMAC SHA-256

A.1.1 Encoding

The JWS Protected Header declares that the data structure is a JWT and the JWS Signing Input is secured using the HMAC SHA-256 algorithm:

{"typ":"JWT",
"alg":"HS256"}

The JWS Payload is:

{"iss":"joe",
"exp":1300819380,
"http://example.com/is_root":true}

The complete JWS using the JWS Compact Serialization (with line breaks for display purposes only):

eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9
.
eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt
cGxlLmNvbS9pc19yb290Ijp0cnVlfQ
.
dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk

A.1.2 Validating

Since the "alg" Header Parameter is "HS256", we validate the HMAC SHA-256 value contained in the JWS Signature by repeating the HMAC computation and comparing the results.

A.2 Example JWS Using RSASSA-PKCS1-v1_5 SHA-256

A.2.1 Encoding

The JWS Protected Header for this example:

{"alg":"RS256"}

This example uses an RSA private key for signing. The complete JWS representation is produced following the same encoding process.

A.2.2 Validating

The RSASSA-PKCS1-v1_5 SHA-256 digital signature is validated by passing the public key, the JWS Signature, and the JWS Signing Input to an RSA signature verifier configured to use SHA-256.

A.3 Example JWS Using ECDSA P-256 SHA-256

A.3.1 Encoding

The JWS Protected Header:

{"alg":"ES256"}

This example uses an Elliptic Curve P-256 key for signing with SHA-256.

A.3.2 Validating

The ECDSA P-256 SHA-256 digital signature is validated using the EC public key and the signature split into R and S components.

A.4 Example JWS Using ECDSA P-521 SHA-512

A.4.1 Encoding

The JWS Protected Header:

{"alg":"ES512"}

The JWS Payload for this example is the ASCII string "Payload".

A.4.2 Validating

The ECDSA P-521 SHA-512 digital signature is validated using the EC public key on the P-521 curve.

A.5 Example Unsecured JWS

An example JWS with no integrity protection (using "alg":"none"). This is only suitable for situations where the payload integrity is protected by other means.

A.6 Example JWS Using General JWS JSON Serialization

A.6.1 JWS Per-Signature Protected Headers

A.6.2 JWS Per-Signature Unprotected Headers

A.6.3 Complete JOSE Header Values

A.6.4 Complete JWS JSON Serialization Representation

This example demonstrates the general JWS JSON Serialization syntax with multiple signatures.

A.7 Example JWS Using Flattened JWS JSON Serialization

This example demonstrates the flattened JWS JSON Serialization syntax optimized for the single signature case.


Note: For complete details of all examples including exact octet sequences, key values, and step-by-step encoding/validation processes, please refer to the official RFC 7515 document at https://www.rfc-editor.org/rfc/rfc7515.txt.