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.

Everything runs in your browser — your data is never sent to any server.

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

  1. Fill in sub, name and the dates: the buttons set iat to now and exp an hour ahead
  2. Add your own claims if needed, for example role or user_id
  3. Enter the secret key and press Sign token
  4. 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

ClaimExample valueWhat it means
sub"user-42"subject identifier: who this token is about
name"Ivan"human-readable name, a public claim with no special meaning
iat1735689600issued at: creation moment in Unix seconds
exp1735693200expiration: 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
nbf1735689600not before: the token is invalid earlier than this moment
email"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

PartWhat it containsHow it is produced
headeralg HS256 and typ JWTfixed JSON in base64url, looks like eyJhbGciOiJI...
payloadyour claims: sub, name, iat, exp and custom onesJSON encoded in base64url
signature32 bytes of binary dataHMAC-SHA-256 over header.payload with the secret
separatora dot between partsparts joined into one string
encodingbase64url instead of base64plus becomes a hyphen, slash becomes underscore
lengtharound 200 characters for this payloaddepends on the number and size of claims
transportthe Authorization headerBearer followed by the token, no line breaks
verificationthe server recomputes the signaturematches — 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

Three parts separated by dots: header.payload.signature. The header describes the signing algorithm; for this generator it is {"alg":"HS256","typ":"JWT"}. The payload carries claims — statements about the user and the token itself: sub for the subject identifier, iat for the issue moment, exp for the expiry moment. The signature guarantees that neither the header nor the payload has changed since issuance. The first two parts are plain encoded JSON that any decoder reads, so secrets must never go into a JWT.

Why is the token signed but not encrypted

Signing and encryption solve different problems. An HS256 signature guarantees integrity: changing even one character of the payload without the secret is impossible, and the server will reject the token. But anyone can read the payload: base64url is not a cipher, just a wrapper that unfolds in one line of code. The rule: a JWT carries a user identifier, a role, a lifetime — things that are safe to show but dangerous to alter. For real secrecy you need JWE or encryption on top, and the generator honestly signs without hiding the content.

What are iat and exp and what format do they use

They are registered time claims, both stored as Unix seconds without milliseconds. iat, issued at, marks when the token was created; exp, expiration time, marks the moment after which the token is invalid and the server must reject it. Setting exp a year out gives you a long-lived token, which makes revoking access awkward, so in practice it is set from minutes to hours. For converting dates back and forth there is the Unix timestamp tool, and the underlying idea is explained in the article on Unix time.

What does the HS256 algorithm do

HS256 means HMAC with the SHA-256 hash: the signature is built on a secret known to both the party that issues the token and the party that verifies it. The same secret signs and verifies, which is why the algorithm is called symmetric. The signature takes 32 bytes and shows up in the token as 43 base64url characters. A short or dictionary-word secret makes brute force realistic, so real systems use a long random string — the password generator can make one, and the signing mechanism itself is dissected in the HMAC generator.

How does HS256 differ from RS256

By the number of keys. HS256 has one shared secret: it both signs and verifies, so any verifying party could technically issue tokens itself. RS256 uses a pair: the private key signs, the public key verifies, and the public key can be handed out to every service — a signature cannot be forged from it. The selection rule is simple: a single service that both issues and verifies tokens lives fine with HS256; several services where only the authorization server signs need RS256. This generator covers HS256, the most common in tutorials and small applications.

Can you trust a token generated in the browser

As study material — yes; as a production artifact — no. The signature is mathematically valid: a server holding the same secret will accept the token. The problem is secret handling: a string typed into a browser form has passed through someone else's computer, input history and extensions, so it cannot be considered reliable. In a real application the secret lives in server environment variables, the backend signs, and the frontend receives the ready token from an API response. The generator shows the red warning deliberately, so the habit of typing a real secret into web forms never forms.

How do I verify the token I got here

Paste it into the JWT decoder — it unfolds the header and payload into readable JSON and shows the signature separately. That confirms the claims landed as intended and the dates became correct seconds. A browser decoder does not fully verify an HS256 signature because that requires the secret — that is the line between parsing a token and verifying it. To feel how the signature reacts to edits, add one extra letter to the payload and compare the signatures: they change completely.

Why base64url instead of plain base64

The plus and slash used by standard base64 travel poorly in URLs and HTTP headers: a plus means a space in an address, and a slash cuts the path. JWT therefore uses base64url: plus is replaced by a hyphen, slash by underscore, and padding characters are dropped as unnecessary. Thanks to this the token passes through redirect URLs, cookies and the Authorization Bearer header without any extra escaping. How the byte-to-character packing itself works is covered in the plain-language guide to Base64.

Related articles

Related tools