toolgarden.xyz
中文
JWTTokenBase64URLAuthentication

What Is a JWT? How to Safely Inspect Header and Payload and Verify the Signature

Take apart a real token segment by segment: Base64URL-decode the Header and Payload, tell whether exp has passed, verify an HS256 signature, and learn what must never go inside and which attacks to defend against.

ToolGarden tools prioritize browser-local processing, so files and text do not need to be uploaded to a server.

Published July 2, 2026Updated October 14, 202611 min readBy ToolGarden

When debugging APIs you keep meeting long strings that begin with eyJ. Those are JWTs. Many people are surprised the first time they paste one into a decoder: the user info and expiry time are all in plain sight. That is because the first two parts of a JWT are encoded, not encrypted. This article uses one complete example token to show how to take it apart, judge whether it has expired, verify the signature, and which security misconceptions to avoid.

JWT structure: three parts separated by dots

A JWT (JSON Web Token, RFC 7519) is three Base64URL texts joined as header.payload.signature. Below is the token used throughout this article (for demonstration only; the secret is demo-secret):

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzg0MjEiLCJuYW1lIjoiQWRhIExvdmVsYWNlIiwicm9sZSI6ImVkaXRvciIsImlhdCI6MTc2MDQwMDAwMCwiZXhwIjoxNzYwNDAzNjAwfQ.32Ly9jxuicwBIgniALk2geoD2re8juuisCtiVCsT834
PartContentDecoded example
HeaderSigning algorithm alg and token type typ{"alg":"HS256","typ":"JWT"}
PayloadClaims: user identifier, role, times{"sub":"user_8421","name":"Ada Lovelace","role":"editor","iat":1760400000,"exp":1760403600}
SignatureSignature computed over the first two parts with a secretBinary data, 43 characters once Base64URL-encoded

Base64URL: why the first two parts can simply be read

Base64URL is the URL-safe variant of Base64: it replaces + with -, / with _, and drops the trailing = padding. Its purpose is to let a token travel in a URL, cookie or HTTP header without extra escaping. It provides no secrecy whatsoever.

Original   : {"a":">>>???"}
Base64     : eyJhIjoiPj4+Pz8/In0=
Base64URL  : eyJhIjoiPj4-Pz8_In0

To decode, reverse it: turn - back into +, _ back into /, pad with = to a multiple of 4 characters, Base64-decode and interpret as UTF-8. A payload with non-ASCII text such as {"name":"张三"} encodes to eyJuYW1lIjoi5byg5LiJIn0 and must be decoded as UTF-8 to avoid garbled output, which the JWT Parser handles. You can also do a manual Base64 decode in the Info Encoder / Decoder page to verify it yourself.

Decoding the example token step by step

  1. Split on . and you must get exactly three parts, otherwise it is not a valid JWS-format JWT. The parser page reports that three parts are expected when the count is wrong.
  2. Decode the first part to get {"alg":"HS256","typ":"JWT"}, which means HMAC-SHA256 signing.
  3. Decode the second part to get the payload. Note that iat and exp are Unix timestamps in seconds, not milliseconds.
  4. iat is 1760400000, which is 2025-10-14 00:00:00 UTC, and exp is 1760403600, which is 2025-10-14 01:00:00 UTC, so the lifetime is exactly 1 hour (3600 seconds).
  5. The page compares the current time with exp and marks the token as expired or valid. Since this example token expired long ago, you will see the expired badge, which makes it a good sample to practice reading.

Quick reference for common claims

ClaimMeaningNote
issIssuerThe server should check it is the expected issuer
subSubject, usually a user IDDo not put email or phone numbers here
audAudience, who the token is forStops a token for service A being used against service B
expExpiration time (seconds timestamp)The server must check it; client-side checks are only for UX
nbfNot beforeThe token is invalid before this time
iatIssued atUseful for judging token age
jtiUnique token IDFor revocation or replay defence; a UUID works

Verifying the signature: how HS256 is computed

An HS256 signature is HMAC-SHA256(secret, header.payload), where header.payload is the exact two Base64URL texts including the dot between them. The resulting bytes are Base64URL-encoded to form the third part. To verify, recompute with the same secret and compare with the third part of the token.

In the verification area of the JWT Parser, enter the secret and click Verify. The page uses the browser Web Crypto API and shows signature valid or invalid. With demo-secret the example token is valid. Change the secret to anything else, or change role from editor to admin and verify with the original signature, and the result is invalid. That is the whole point of a signature: any tampering with the first two parts breaks the match.

The limits, stated plainly: the page only verifies HS256, a symmetric algorithm, and not RS256, ES256 or other public-key algorithms. It checks whether the signature matches the secret, and does not replace the server's checks of exp, iss and aud. Decoding by itself verifies nothing.

What must not go in the Payload

Because anyone can decode the payload, never put in passwords, API keys, national ID numbers, card numbers or full phone numbers. Include only the minimum identifying information, such as user ID, role, tenant ID and times. If something truly must be transported confidentially, use JWE (JSON Web Encryption), or keep sensitive data on the server and let the token carry an opaque reference.

Common JWT security pitfalls

ProblemExplanationDefence
alg set to noneAn attacker changes the header alg to none and strips the signature; a server that accepts it lets the token throughFix an allowlist of algorithms on the server and reject none
Algorithm confusionThe server uses an RS256 public key as the HS256 secret, letting an attacker forge signatures with the public keyEnforce the algorithm by key type and never trust the alg in the token
Decode without verifyingThe frontend trusts the payload, for example to show an admin menuMake every authorization decision on the server after verifying the signature
Tokens leaking into logsFull tokens left in URL parameters, access logs and monitoringNever put tokens in URLs; redact them in logs
Long lifetimesA leaked token stays usable for its whole lifetimeUse short access token lifetimes with a refresh mechanism
No active revocationJWTs are stateless, so by default they cannot be withdrawn after issueKeep a denylist or jti records, or shorten lifetimes

Diagnosing "invalid token" in order

  1. Count the parts first. If it is not three, you probably missed a piece when copying, or the value carries a Bearer prefix, quotes or a line break.
  2. Decode the Header and confirm alg matches what the server expects.
  3. Decode the Payload, check whether exp has passed (seconds, not milliseconds), then check that iss and aud match the server configuration.
  4. Clock difference between server and client: a few minutes of skew can break an nbf or exp check, and servers typically allow a small tolerance.
  5. Verify the signature last: confirm the secret belongs to the right environment. Different production and test secrets are the most common cause.

Hands-on: why tampering with the payload breaks the signature

The most direct way to understand a signature is to break one yourself. Decode the second part of the example token, change role from editor to admin, Base64URL-encode it again and put it back as the second part, leaving the first and third parts untouched. Paste the new token into the JWT Parser: decoding succeeds and the payload plainly shows role as admin, but entering demo-secret in the verification area gives signature invalid.

The reason is that the third part was computed over the original two parts. Changing the second part changes the signed content, so the signature the server recomputes differs from the one carried in the token. To make a modified token pass, an attacker would need the secret to sign it again, which is exactly why the secret must stay confidential. The experiment also shows that a successful decode only means the format is right, never that the content can be trusted.

  • Changing only the Header or only the Payload invalidates the signature either way.
  • Re-encoding the whole token with unchanged content can still fail in a strict implementation if the text differs, for example by gaining padding equals signs.
  • Strip the Bearer prefix from an Authorization header value first, otherwise it is judged to have the wrong number of parts or to fail decoding.

Cross-check the signature on the command line

If you would rather not depend entirely on a web page, compute it yourself with openssl and understand the details of HS256. Run this on the first two parts of the example token, kept exactly as they are including the dot between them:

printf '%s' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzg0MjEiLCJuYW1lIjoiQWRhIExvdmVsYWNlIiwicm9sZSI6ImVkaXRvciIsImlhdCI6MTc2MDQwMDAwMCwiZXhwIjoxNzYwNDAzNjAwfQ' \
  | openssl dgst -sha256 -hmac 'demo-secret' -binary \
  | base64 | tr '+/' '-_' | tr -d '='

The output is 32Ly9jxuicwBIgniALk2geoD2re8juuisCtiVCsT834, identical to the third part of the token. Two details are easy to get wrong. First, use printf rather than echo, because echo appends a newline and the signature will not match. Second, after Base64 you must swap + and / for - and _ and strip =, which is what makes it Base64URL. Run this once and the question of what exactly is signed disappears: it signs the text of the first two parts itself, not the decoded JSON.

JWT versus server-side sessions

DimensionJWT (stateless token)Server-side session
Server storageNo need to store each tokenSession data must be stored, and shared across instances
Horizontal scalingAny instance can verify it given the secretNeeds shared sessions or sticky routing
Active revocationHard, needs a denylist or short lifetimesJust delete the session
Payload sizeFull token on every request, larger with more claimsOnly a short session ID is sent
Information visibilityPayload readable by the holderData stays on the server
Good fitPassing identity between services, short-term authorizationAdmin systems that need forced logout or frequent permission changes

A common compromise is a JWT access token with a very short lifetime (minutes to a few tens of minutes) plus a refresh token that is an opaque random string stored on the server and revocable at any time. You get the convenience of stateless verification and still keep the ability to revoke, at the cost of implementing a refresh flow.

One more reminder when troubleshooting: do not use a frontend exp check to decide whether to trust the user. Reading exp in the browser is only suitable for experience improvements, such as refreshing early when a token is about to expire or prompting a re-login. The actual allow or deny decision must be made by the server after verifying the signature, expiry, issuer and audience. Drawing that line clearly prevents most JWT-related incidents and saves detours while debugging.

When not to use JWT, or not to rely on this page alone

  • Scenarios needing instant revocation, such as forced logout: server-side sessions are more direct, and JWTs need an extra denylist mechanism.
  • Storing sensitive user data: JWTs are not encrypted by default. Use server-side storage or JWE.
  • Verifying RS256, ES256 or other asymmetric signatures: this page does not support them. Use the JWT library of your language.
  • Using the result as an authorization basis: any web tool is only for troubleshooting, and authorization must be done by the server.

Frequently asked questions

Q.Is the JWT payload encrypted? Can I store a password in it?

It is not encrypted, only Base64URL encoded, so anyone holding the token can decode and read it. Never put passwords, secrets, ID numbers or full card numbers in it. If something must be transported confidentially, use JWE, or put only an opaque identifier in the token.

Q.Do I need the secret to decode a JWT?

No. Decoding just restores Base64URL text, and anyone can do it. The secret is only used to verify the signature, proving the content was not tampered with and was issued by a holder of the secret.

Q.Is exp in seconds or milliseconds?

Times in the JWT standard (exp, iat, nbf) are Unix timestamps in seconds. Treating them as milliseconds yields a date in January 1970. You can confirm with the Timestamp Converter.

Q.Why does signature verification fail even though the token looks right?

Common causes are the wrong secret (environment mix-up), stray spaces or newlines in the secret, or the token being altered in transit. Also, if alg is not HS256, for example RS256, this page cannot verify it.

Q.What is the difference between Base64 and Base64URL?

Base64URL replaces + with -, / with _ and omits the trailing = padding so the output fits in URLs and HTTP headers. There is no difference in confidentiality.

Q.Is it safe to decode a JWT in a web page?

The parser runs locally in the browser and does not upload the token. But a token is itself a credential, so be careful anywhere you paste it: prefer test-environment tokens, keep production tokens out of screenshots and shared screens, and clear the clipboard afterwards.