What is a JWT generator?
A JWT generator creates a JSON Web Token (JWT), the compact string that apps and APIs use to carry identity and permission claims. You write a JSON header and payload, choose an algorithm and a secret, and the tool signs them into a token you can copy straight into a request, a test or a config file.
This free online JWT encoder signs tokens with HMAC (HS256, HS384 and HS512) using the Web Crypto API in your browser. It also decodes and verifies tokens, shows readable dates for iat, exp and nbf, and exports code for Node.js, Python and PHP. Your secret and data are never uploaded.
The structure of a JSON Web Token
A JWT is three Base64URL strings joined by dots: header.payload.signature.
- Header: JSON describing the token, usually
{"alg":"HS256","typ":"JWT"}. - Payload: JSON with the claims, such as the user ID and the expiry time.
- Signature: an HMAC of
header.payloadmade with your secret. If anyone edits the header or payload, the signature no longer matches.
Base64URL is Base64 with - and _ instead of + and /, and no = padding, so a token is safe to put in a URL or HTTP header.
Common JWT claims
| Claim | Name | Meaning |
|---|---|---|
iss | Issuer | Who created and signed the token, for example your auth server URL. |
sub | Subject | Who the token is about, usually a user ID. |
aud | Audience | Who the token is meant for, such as an API name. Receivers should reject tokens meant for someone else. |
exp | Expiration time | Unix timestamp in seconds after which the token must be rejected. |
nbf | Not before | Unix timestamp before which the token must not be accepted. |
iat | Issued at | Unix timestamp of when the token was created. |
jti | JWT ID | A unique ID, useful for revocation lists and replay protection. |
You can add any custom claims you like, such as role or scope. Keep them small, because the token is sent with every request.
JWT signing algorithms: HS256, HS384, HS512
| Algorithm | Type | Hash | Recommended secret |
|---|---|---|---|
HS256 | HMAC, shared secret | SHA-256 | 32+ random bytes |
HS384 | HMAC, shared secret | SHA-384 | 48+ random bytes |
HS512 | HMAC, shared secret | SHA-512 | 64+ random bytes |
RS256 | RSA, key pair | SHA-256 | Private key signs, public key verifies |
ES256 | ECDSA, key pair | SHA-256 | Private key signs, public key verifies |
HMAC algorithms use one secret for both signing and verifying, so they suit a single service or a small set of trusted services. If many services must verify tokens without being able to create them, use a key-pair algorithm such as RS256 or ES256. This tool supports the HS family only.
JWT security basics
- Use a long random secret. Short or guessable secrets can be brute-forced offline.
- Always set
exp. Short-lived access tokens limit the damage if one leaks. - Fix the allowed algorithm on the server. Do not trust the
algvalue in the token header, and never acceptnone. - Validate
issandaud. Reject tokens that were issued by or meant for someone else. - Send tokens over HTTPS only and store them carefully on the client.
- Verify on the server. Decoding a token in the browser proves nothing about whether it is valid.
Common JWT mistakes and how to fix them
- Timestamps in milliseconds. JWT times are Unix seconds. JavaScript's
Date.now()returns milliseconds, so divide by 1000. - Invalid signature after editing. Changing any character in the header or payload breaks the signature. Re-sign the token.
- Wrong secret encoding. Some libraries treat the secret as Base64. This tool uses the secret as plain UTF-8 text, so match that in your code.
- Clock skew. If servers disagree on the time,
nbfandexpchecks can fail. Allow a few seconds of leeway. - Huge payloads. Large tokens bloat every request and may exceed header size limits.
Create a JWT in Node.js, Python and PHP
The Code tab generates a snippet for your current header, payload and secret. Here is the basic idea in each language.
Node.js (jsonwebtoken)
const jwt = require("jsonwebtoken");
const token = jwt.sign({ sub: "1234", role: "admin" }, process.env.JWT_SECRET, {
algorithm: "HS256",
expiresIn: "1h"
});
Python (PyJWT)
import jwt, os, datetime
payload = {"sub": "1234", "exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1)}
token = jwt.encode(payload, os.environ["JWT_SECRET"], algorithm="HS256")
PHP (firebase/php-jwt)
use Firebase\JWT\JWT;
$payload = ['sub' => '1234', 'exp' => time() + 3600];
$token = JWT::encode($payload, getenv('JWT_SECRET'), 'HS256');
What are JWTs used for?
- API authentication: send a bearer token with each request instead of a session cookie.
- Single sign-on: pass identity between services in OAuth 2.0 and OpenID Connect flows.
- Short-lived authorization: email verification and password reset links with an expiry.
- Service-to-service calls: prove which internal service is calling another.
- Testing and debugging: create tokens with specific claims to test how your API behaves.
Need other utilities? Browse all developer tools, try the regex tester, or use our image compressor.