JWT Encoder

Create JSON Web Tokens with HS256, HS384 or HS512 signatures. Enter a JSON payload and secret key.

Was this tool helpful? Rate it:

What is a JWT encoder?

A JWT encoder builds a signed JSON Web Token from three inputs: a JSON payload of claims, a secret key and a signing algorithm. MavexTech’s encoder creates tokens signed with HMAC — HS256, HS384 or HS512 — using the browser’s Web Crypto API, so the payload and the secret never leave your device. Use it to create test tokens for an API you are building, to reproduce a bug in token validation, or simply to see how a JWT is put together.

How to create a JWT

  1. Write the payload as valid JSON, for example {"sub":"user_42","role":"editor","iat":1760486400,"exp":1760490000}.
  2. Enter the secret key that your server uses to verify tokens. For testing, use a throwaway value rather than a production secret.
  3. Pick the algorithm — HS256 is the most widely supported.
  4. Click Generate JWT and copy the token. Send it in an HTTP header such as Authorization: Bearer <token>.

How a JWT is built (RFC 7519)

A JSON Web Token, defined in RFC 7519, is three Base64url strings joined by dots: header.payload.signature. This tool creates the compact JWS form:

  1. Header — the tool always uses {"alg":"HS256","typ":"JWT"} (or HS384/HS512). Base64url-encoded, that header becomes eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
  2. Payload — your JSON text, UTF-8 encoded and Base64url-encoded exactly as typed.
  3. Signature — HMAC-SHA256(secret, header + "." + payload), Base64url-encoded without = padding.

Base64url is ordinary Base64 with + replaced by -, / replaced by _ and trailing = removed, so the token is safe in URLs and headers.

Worked example (checked against the live tool and Python’s hmac module)

Payload {"sub":"user_42","role":"editor","iat":1760486400,"exp":1760490000}, secret change-this-to-a-long-random-secret, algorithm HS256 produces:

PartValue
HeadereyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
PayloadeyJzdWIiOiJ1c2VyXzQyIiwicm9sZSI6ImVkaXRvciIsImlhdCI6MTc2MDQ4NjQwMCwiZXhwIjoxNzYwNDkwMDAwfQ
Signature5GIWsJ43-o4CrTWcu6EJXRpahV4AXY0ryjY16m8nGnU

Here iat 1760486400 is 15 October 2025 00:00:00 UTC (05:30 IST) and exp 1760490000 is one hour later. Paste the full token into the JWT Decoder to read the claims back. Note that the tool’s default sample payload has exp 1893456000, which is 1 January 2030 00:00:00 UTC, so the sample token is not yet expired; set your own exp for real use.

Registered claims you can put in the payload

ClaimNameMeaning
issIssuerWho created and signed the token
subSubjectWhom the token is about, usually a user ID
audAudienceWhich service the token is intended for
expExpiration timeUnix time (seconds) after which the token must be rejected
nbfNot beforeUnix time before which the token must not be accepted
iatIssued atUnix time when the token was created
jtiJWT IDUnique identifier, useful for revocation lists and replay protection

All times are NumericDate values: seconds since 1 January 1970 UTC, not milliseconds. A JavaScript Date.now() value must be divided by 1000.

HS256 vs HS384 vs HS512

AlgorithmHashSignature sizeSignature length in the tokenSuggested minimum secret
HS256SHA-25632 bytes43 characters32 random bytes
HS384SHA-38448 bytes64 characters48 random bytes
HS512SHA-51264 bytes86 characters64 random bytes

RFC 7518 requires an HMAC key at least as long as the hash output. The signature lengths above were measured on the tool’s output. For most APIs HS256 with a strong, random secret is enough; a longer hash does not rescue a weak password-like secret.

Security caveats

  • A JWS is signed, not encrypted. Anyone holding the token can Base64url-decode the payload. Never put passwords, Aadhaar or card numbers, or other sensitive personal data in it. Use JWE if the contents must be secret.
  • Weak secrets can be brute-forced offline. An attacker with one token can try guesses without contacting your server. Generate the key with a cryptographic random source, for example the Password Generator at 64 characters.
  • Pin the algorithm when verifying. Libraries should accept only the algorithm you expect. Rejecting "alg":"none" and preventing HMAC/RSA key confusion are classic JWT hardening steps.
  • Validate claims, not just the signature — check exp, nbf, iss and aud on every request.
  • Keep access tokens short-lived (minutes, not months) and use refresh tokens or server-side sessions for long logins, because a stateless JWT cannot easily be revoked before it expires.
  • HMAC means shared secrets. Every service that verifies an HS256 token can also mint one. When many services only need to verify, an asymmetric algorithm such as RS256 or ES256 is a better fit; this tool does not create those.

Limitations & notes

The tool encodes the payload text exactly as typed, including spaces and line breaks, so a pretty-printed payload gives a longer token than the same JSON on one line — both are valid. It refuses to sign a payload that is not a valid JSON object and shows an error instead (the JSON Formatter helps find the mistake). The header is fixed to alg and typ; custom header fields such as kid are not supported. Although everything runs locally, treat any secret you paste into a web page as exposed and use test keys.

Frequently asked questions

Is a JWT encrypted?

No. A standard signed JWT only guarantees integrity: the payload is Base64url text that anyone can decode. Use JWE (JSON Web Encryption) if the contents must be hidden, and never store passwords or personal data in the payload.

Which algorithm should I choose, HS256 or HS512?

HS256 is supported everywhere and is secure with a random secret of at least 32 bytes. HS512 gives a longer signature and needs a 64-byte key. Pick whatever your verifying library is configured to accept.

How long should a JWT be valid?

Access tokens are commonly kept to minutes or an hour, with longer-lived refresh tokens stored securely. Set exp in Unix seconds, for example iat plus 3600 for one hour.

Why does my server say the token is invalid?

The usual causes are a different secret (including extra spaces), a different algorithm, an expired exp, a wrong aud or iss, or a payload that is not valid JSON. Decode the token and compare each part.

Can I make RS256 or ES256 tokens here?

No. This encoder signs with HMAC only (HS256, HS384, HS512). Asymmetric algorithms need a private key and are best created in your backend library.

Why use JWT instead of server sessions?

A JWT carries its own claims, so any server with the key can verify it without a shared session store, which suits APIs and microservices. The trade-off is that revoking a token before it expires needs extra work.

Is it safe to paste my production secret here?

The signing runs in your browser and nothing is uploaded, but as a habit use test secrets in any online tool and keep production keys in your server configuration or a secrets manager.

Related tools

JWT Decoder · Base64 Encoder/Decoder · Hash Generator · Password Generator · JSON Formatter

Copied