Reading — step 1 of 5
Read
~1 min readSigning & Verification
HS256 Signing
HS256 = HMAC with SHA-256. Symmetric: same key signs and verifies.
signing_input = base64url(header) + "." + base64url(payload)
signature = HMAC-SHA256(secret_key, signing_input)
jwt = signing_input + "." + base64url(signature)
Verification:
- Split JWT on dots into 3 parts.
- Recompute HMAC-SHA256 over
header.payload. - Compare to the decoded signature.
- Use constant-time comparison to avoid timing attacks.
python
Pros: simple, fast, small keys (32+ bytes random). Cons: anyone with the verification key can ALSO sign new tokens. Bad for cross-organization scenarios where the verifier shouldn't be able to forge.
For those: use RS256 or ES256 (asymmetric — covered next).
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…