JWT Generator
Build a JWT with sub, name, iat, exp and custom claims and sign it with HS256 via Web Crypto in your browser. Three-part token output and a decoder link.
Why generate a JWT by hand
A JWT generator is what you reach for when you need a real signed token for testing: checking how the frontend handles an expired exp, feeding your own sub and role to a test authorization flow, or taking apart what a JSON Web Token is made of, hands on. The token is assembled per RFC 7519: header and payload are encoded in base64url, an HMAC-SHA-256 signature is computed over them with your secret, and the three parts are joined with dots. Everything is computed in the browser through Web Crypto with no server involved. For learning, it is the shortest path: change one claim and immediately watch the signature change.
What the generator offers
- Builds the payload from sub, name, iat and exp fields with automatic Unix-second dates
- Accepts arbitrary key–value claims, keeping numeric values as numbers
- Signs the token with HS256 through Web Crypto, no external libraries
- Shows the finished token and each of the three parts separately, one-click copy
- Masks the secret and warns that browser-side signing is for tests only
How to get a token
- Fill in sub, name and the dates: the buttons set iat to now and exp an hour ahead
- Add your own claims if needed, for example role or user_id
- Enter the secret key and press Sign token
- Copy the finished three-part string and check it in the decoder
How the signature is built
A token consists of three dot-separated parts. The first is the header; for HS256 it is a fixed JSON with alg and typ fields, so its base64url form always looks the same. The second is the payload — your claims as JSON. Each part is encoded in base64url: a base64 variant where plus becomes a hyphen, slash becomes underscore, and padding is dropped so the token lives comfortably in the Authorization header. The third part is the signature: HMAC-SHA-256 over the string first-part.second-part, keyed by your secret. The key is imported through crypto.subtle.importKey, the signature comes from crypto.subtle.sign, and all of it happens in your browser.
Claims most often found in a payload
| Claim | Example value | What it means |
|---|---|---|
| sub | "user-42" | subject identifier: who this token is about |
| name | "Ivan" | human-readable name, a public claim with no special meaning |
| iat | 1735689600 | issued at: creation moment in Unix seconds |
| exp | 1735693200 | expiration: after this moment the token is invalid |
| iss | "auth.example.com" | who issued the token |
| aud | "api.example.com" | which audience the token is for |
| role | "admin" | an application-specific claim the server interprets itself |
| jti | "a1b2c3" | unique token id, useful for revocation |
| nbf | 1735689600 | not before: the token is invalid earlier than this moment |
| "ivan@example.com" | another public claim, readable by everyone without the secret |
The first six claims in the list are registered in RFC 7519; the rest appear as public or private agreements between your own services.
Where a signed token is needed right now
Testing authorization is the first scene. A frontend developer checks what happens when exp expires: set exp a minute ahead, wait, and see whether the re-login screen appears. A backend developer receives a token from the frontend and wants to make sure the middleware correctly rejects a tampered signature: generate a valid token, change one letter, and both cases are laid out. QA prepares a fixture set: a valid token, an expired one, a token without a role, a token with someone else's sub — all of it takes minutes.
The second scene is learning and teardown. On a real example you can see how the payload becomes a string, how the signature reacts to a single changed character, and why a server will not accept a token with an edited claim. A student or junior who has assembled a token by hand no longer confuses signing with encryption and understands why a password never goes into the payload. The full format walkthrough lives in the article JWT: what is inside a token — it complements the hands-on practice here well.
- Fixtures for automated tests: valid, expired and tampered tokens
- Checking exp handling on the frontend and middleware on the backend
- Debugging role and sub in authorization without running an auth server
- Study assignments on the JWT format and HMAC signatures
- Demos and documentation: show the team a real token, not a mock
Typical mistakes when generating tokens
The first mistake is using a real production secret in the browser form. Even if the page sends nothing over the network, the secret stays in browser input history and in extension memory, and the habit of typing it into third-party forms is dangerous in itself. A generator deserves a test secret such as a string of twelve random characters; real keys stay on the server and never touch the form.
The second mistake is mixing up seconds and milliseconds in iat and exp. The standard demands seconds; pass milliseconds and the number lands far in the future, so a token with a formally correct exp lives for centuries. The third is forgetting the payload is readable by everyone: passwords, card numbers and personal data do not go there, signed or not. And the fourth is believing an HS256 signature protects the content from reading: it protects only against modification.
- Real secrets never go into browser generators, only test ones
- iat and exp are Unix seconds, no milliseconds
- The payload is not encrypted: no secret data belongs there
- The signature guarantees immutability, not secrecy of content
- An overly long exp makes access revocation impossible
- Changing the payload by one symbol changes the entire signature
Worked example: a token in three parts
Take a minimal payload: sub set to user-1, name set to Ivan, iat and exp filled by the buttons. The HS256 header is fixed, so its base64url form is always the same. The payload after packing comes to roughly a hundred characters — Cyrillic in JSON becomes UTF-8, so Ivan takes more bytes than Latin text. The signature is computed over the header.payload string with your secret and turns into 43 base64url characters. The parts joined by dots make up the finished token, a couple hundred characters long, easy to copy in one go.
Next it helps to look at the token through a decoder: it shows the same claims and the signature separately. Change one letter in the payload and re-sign — the signature changes entirely, because HMAC spreads the change across all 32 bytes. Change a letter and do not re-sign — the server rejects the token at signature verification. The table below shows what goes where.
How the finished token comes together
| Part | What it contains | How it is produced |
|---|---|---|
| header | alg HS256 and typ JWT | fixed JSON in base64url, looks like eyJhbGciOiJI... |
| payload | your claims: sub, name, iat, exp and custom ones | JSON encoded in base64url |
| signature | 32 bytes of binary data | HMAC-SHA-256 over header.payload with the secret |
| separator | a dot between parts | parts joined into one string |
| encoding | base64url instead of base64 | plus becomes a hyphen, slash becomes underscore |
| length | around 200 characters for this payload | depends on the number and size of claims |
| transport | the Authorization header | Bearer followed by the token, no line breaks |
| verification | the server recomputes the signature | matches — the token is genuine; otherwise rejected |
None of the three parts contains the secret: the secret is needed only at signing and at verification and never enters the token itself.
What to read and what pairs with the generator
The generator and the decoder make a pair: one assembles a token, the other takes it apart. Once the token is ready, open the JWT decoder and check the claims. To see the math behind the signature, open the HMAC generator — it shows how a message and a key become 32 signature bytes, with test vectors to check against. Real secrets are made as random strings: the password generator suits that, and the length and entropy requirements are covered in the article on a strong password.
For a deeper dive the standards remain the source: RFC 7519 describes JWT, and RFC 7515 describes the JWS signing scheme used here. On this site the format is taken apart piece by piece in the article JWT: what is inside a token, and the base64url packing in the guide to Base64. Together these four texts cover practice and theory: assemble, parse, understand the signature, understand the packing.
- Generator and decoder complement each other: build, then verify
- The HMAC generator shows signature math on verifiable vectors
- Real secrets are generated as random strings and kept on the server
- RFC 7519 defines the claims, RFC 7515 defines the signature
- For several services with separate keys, look toward RS256
Frequently asked questions
What is a JWT made of
Why is the token signed but not encrypted
What are iat and exp and what format do they use
What does the HS256 algorithm do
How does HS256 differ from RS256
Can you trust a token generated in the browser
How do I verify the token I got here
Why base64url instead of plain base64
Related articles
HMAC Request Signing: Why APIs Sign Requests and How the Signature Is Computed
Why API requests and webhooks carry an HMAC signature, how HMAC works in plain words, why a signature is not encryption, timing-safe comparison, JWT HS256, and a step-by-step HMAC-SHA-256 calculation with a verified test vector.
HS256 vs RS256: Which JWT Signature to Choose
What HS256 and RS256 actually are, when a shared secret is enough, when an RSA key pair becomes necessary, signature sizes and speed compared, how the algorithm confusion attack works, and how to verify a token under both algorithms in practice.
Related tools
Base64 Encode / Decode
Encode text to Base64 or decode Base64 strings with full Unicode support
URL Encode / Decode
Encode and decode URLs with full or component encoding modes
Encoding Detector
Detect text and file encoding online: UTF-8, UTF-16, ASCII, Windows-1251, KOI8-R. Confidence score, byte details and a side-by-side preview of how the text looks in each candidate encoding
HTML Entity Encode / Decode
Encode and decode HTML entities like < > & "
JWT Token Decoder
Decode JWT tokens to view header, payload, and signature as formatted JSON
ROT13 Cipher
Encode or decode text using the ROT13 substitution cipher
Morse Code Translator
Convert text to Morse code and back with visual representation and audio playback
Binary Translator
Convert text to binary (0s and 1s) and back with byte-level breakdown