手把手解码 JWT:三段结构与常见陷阱
header/payload/signature 逐段解析,exp/iat 声明解读,解耦“看懂”与“验签”两件事。
A JSON Web Token looks like three random strings glued with dots, but each part is just encoded data. Learning to read it takes two minutes and pays off in every auth debugging session.
The anatomy of the three parts
Split the token on dots: header.payload.signature. Header and payload are JSON objects encoded with URL-safe Base64 — not encrypted. The signature is raw bytes produced by HMAC or an RSA/ECDSA operation over the first two parts.
You can decode the first two parts by hand: add padding, swap - for + and _ for /, then Base64-decode. Or simply paste the token into the JWT Decoder, which formats the JSON and flags standard claims.
Claims worth reading first
exp— expiry time as a Unix timestamp. Convert it with the Timestamp Converter when a session dies mysteriously.issandaud— who issued the token and who it is for. Mismatches cause most unexpected 401 responses.sub— the user or system subject the token authorizes.
Decoding is not verification
Anyone can decode a JWT — that is its design. Verification means recomputing the signature with the signing key and comparing it; a decoded token proves nothing. Never make authorization decisions from payload content alone.
Common debugging scenarios
- Expired-token errors: check
expagainst your server clock, not your laptop clock. - Garbled signature: normal — it is binary data, not text.
- Wrong audience: compare
audwith the value your API actually verifies.
The JWT Decoder shows the header, the formatted payload and claim-by-claim explanations entirely offline, so even production-shaped tokens are safe to inspect.
相关指南
文中提到的工具
JWT Decoder
Decode a JWT header and payload into readable JSON with formatted dates for exp/iat/nbf, signature state and expiry status. Safe: verification never happens in the browser.
Open tool →Base64 Encoder / Decoder
Encode text to Base64 or decode it back in one click, plus image ⇄ Base64 data-URL conversion with drag & drop. Free, instant and 100% browser-based — nothing is uploaded.
Open tool →SHA-256 Generator
Compute the SHA-256 digest of any text instantly — with SHA-1, SHA-384 and SHA-512 alongside. Uses WebCrypto when available, with a pure-JS fallback. Includes HMAC demo mode.
Open tool →