liveBook · Manning

HS256

As explained in Secure APIs

HS256 is the JWT algorithm identifier for HMAC using SHA-256.

HS256 is the JWT algorithm identifier for HMAC using SHA-256. It creates a signature from the base64url-encoded header and payload, joined by a dot, and a secret key. The signature provides integrity and authenticity: changing the token makes verification fail. section 7.2.2

HS256 is symmetric: the same secret signs and validates tokens. Every verifier therefore needs the signing key, increasing the risk of key exposure. Keep the key out of source code and obtain it from the environment or another protected configuration source. section 8.2

Issuing an HS256 token with PyJWT

A Python service can supply a payload, signing key, and algorithm to PyJWT: jwt.encode(payload=payload, key="password", algorithm="HS256"). The example includes issuer, subject, audience, issued-at, and one-hour expiration claims. The hardcoded password is illustrative; production code should retrieve the secret from the environment. section 8.2

HS256 does not hide JWT claims. Because the header and payload are base64url-encoded JSON, token holders can inspect them. Use token encryption when the claims are sensitive; JWE provides a standard encrypted-token format. section 7.2.2

How Secure APIs covers it

How deep it goes
Explains the signing input, HMAC-SHA256, symmetric key use, and PyJWT issuance, while deferring deeper cryptographic internals.
Examples
Uses a reserved-claims JWT header and payload, a PyJWT script, a generated token, and jwt.io signature verification.
What it assumes
Assumes basic JWT structure and JSON familiarity while introducing the signing input, HMAC key, and reserved claims through examples.
What you can do after
Builds an HS256 JWT with PyJWT and recognizes key-sharing and claim-visibility trade-offs.
How it connects
Connects HS256 with JWT, HMAC, SHA-256, symmetric signing, base64url encoding, RS256, and JWE.

Also explained in

Compare how 2 books explain HS256 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.