# JWT Encoder and Decoder

> Decode a JSON Web Token into its header and claims, check an HS256 signature against a secret, or sign a JSON payload. Runs in your browser.

Use it online (free, runs in your browser): https://directory.milunir.com/developer-tools/encoders-decoders/jwt-encoder-and-decoder/

Paste a token to see its header and claims, with exp, iat and nbf turned into UTC dates. Switch to Verify and enter the secret to recompute the HMAC-SHA256 signature and compare it, or to Sign to build a new HS256 token. The RFC 7515 sample key verifies its token to dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk.

A JSON Web Token is three base64url strings joined by dots: a header, a set of claims and a signature. When a login fails or an API answers 401, the first question is usually what the token actually says and whether it was signed with the key you think. This page answers both. Decode shows every header field and claim in a table, with timestamps as readable UTC dates. Verify recomputes the HS256 signature from your shared secret and tells you whether it matches. Sign builds a fresh HS256 token from a JSON payload, which helps when you need a test token for a local API. Everything runs in this page, so the token and the secret never leave your device. The limit: signing and verifying cover HS256 only; RS256 and ES256 tokens can be decoded but not checked here.

## How to use

1. **Pick a job**: Choose Decode to read a token, Verify to check its signature, or Sign to create a new one.
2. **Paste the token or payload**: Paste the full JWT, with or without the Bearer prefix, or type the claims as a JSON object.
3. **Enter the secret**: For Verify and Sign, type the shared HS256 key. Under More options, tick the base64url box if your key is stored that way.
4. **Read the claims table**: Each header field and claim appears with its value and meaning; copy any single value from its row.

## Examples

### Read the claims of the RFC 7519 token

- Mode: Decode
- JWT: eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk

Result: Result: { "iss": "joe", "exp": 1300819380, "http://example.com/is_root": true } Details: Signature not checked

Decoding needs no secret. The exp claim 1300819380 is shown as 2011-03-22 18:43:00 UTC, which tells you the token expired long ago.

### The RFC 7515 HS256 example

- Mode: Verify
- JWT: eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
- Secret: AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow
- Secret is base64url-encoded: Yes

Result: Result: Signature verified Details: 3 claims

The standard's own token checks out against its 64-byte key, given as base64url, so the signature is valid and no key-length warning appears.

### Sign a payload with HS256

- Mode: Sign
- Payload (JSON): {"sub":"1234567890","name":"John Doe","iat":1516239022}
- Secret: your-256-bit-secret

Result: Result: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c Details: 155 characters

The widely used sample payload and secret give the familiar sample token. The 19-byte secret is flagged as shorter than the 32 bytes RFC 7518 asks for.

## How it works

`signature = base64url( HMAC-SHA256( secret, base64url(header) + "." + base64url(payload) ) )`

- `header`: the JSON object naming the algorithm, here {"alg":"HS256","typ":"JWT"}
- `payload`: the JSON object of claims such as sub, iat and exp
- `secret`: the shared key, as UTF-8 text or as base64url-decoded bytes

Decoding reverses base64url (RFC 4648 section 5, the URL-safe alphabet with no padding) on the first two parts and parses each as JSON. Verifying runs HMAC with SHA-256 (RFC 2104 over FIPS 180-4) on the exact header and payload text from the token, then compares the base64url result with the third part character for character. Signing compacts your JSON first, so whitespace in the box does not change the token. Numeric dates are seconds since 1970-01-01 UTC, as RFC 7519 defines NumericDate.

Sources:

- [RFC 7519: JSON Web Token (JWT)](https://www.rfc-editor.org/info/rfc7519/), RFC Editor
- [RFC 7515: JSON Web Signature (JWS)](https://www.rfc-editor.org/info/rfc7515/), RFC Editor

## When not to use it

- Do not paste a live production token into any page you do not control; rotate it after debugging.
- Tokens signed with RS256, ES256 or PS256 need a public key, which this page cannot check.
- Encrypted tokens (JWE, five parts) cannot be read without the decryption key.

## Common mistakes

- Treating a decoded token as trusted: anyone can read and rewrite the claims until the signature is checked.
- Using a short HS256 secret like secret; RFC 7518 asks for at least 32 bytes of key.
- Entering a base64url key as plain text, which signs with different bytes and fails verification.
- Reading exp as milliseconds; JWT dates count seconds since 1970.

## Questions

### How do I use a JWT debugger to see what is inside a token?

Paste the token into Decode. The header and payload are only base64url-encoded, not encrypted, so they can be read without any key. The table lists each field, its value and what the registered claim means, and exp, iat and nbf are shown as UTC dates so you can see at a glance whether the token has expired.

### How does a JWT verifier check that a token is genuine?

It takes the first two parts of the token exactly as they appear, computes HMAC-SHA256 over them with the shared secret, base64url-encodes the 32-byte result and compares it with the third part. If even one character of the header or claims was changed, or the secret differs, the two strings do not match and Verify reports an invalid signature.

### Can I decode a JWT offline without sending it to a server?

Yes. The decoding, the HMAC and the SHA-256 are all computed in JavaScript inside this page, and nothing is uploaded. Once the page has loaded, it keeps working with the network off, which makes it suitable for tokens from a local or internal system.

### How long should a JWT secret be for HS256, is 32 characters enough?

RFC 7518 section 3.2 requires an HS256 key of at least 256 bits, which is 32 bytes. Thirty-two random ASCII characters meet the byte count, but a phrase people can guess does not give 256 bits of strength. A random 32-byte value stored as base64url is the safer choice; the page warns when a key is under 32 bytes.

### How do I generate a JWT signed with HS256?

Choose Sign, type your claims as a JSON object, for example {"sub":"42","exp":1767225600}, and enter the secret. The page adds the header {"alg":"HS256","typ":"JWT"}, base64url-encodes both parts, signs them and returns the finished token, ready to send in an Authorization: Bearer header.

### Will a token from this generator match one made with a Python JWT library?

Usually the signature checks out either way, but the token text can differ. PyJWT and similar libraries may order header fields or format JSON differently, which changes the base64url strings and so the signature. Both tokens still verify with the same secret, because each signature covers its own exact header and payload bytes.

## Use from code or an AI agent

Free JSON API, no key needed. The answer is in `result.stats.primary`.

```bash
curl -X POST https://api.tools-directory.workers.dev/v1/tools/jwt-encoder-and-decoder \
  -H 'Content-Type: application/json' \
  -d '{"inputs":{"mode":"decode","token":"eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"}}'
```

- Inputs (JSON Schema): https://directory.milunir.com/api/v1/tools/jwt-encoder-and-decoder.json
- MCP server: https://api.tools-directory.workers.dev/mcp (tool `jwt_encoder_and_decoder`)
- Docs: https://directory.milunir.com/docs/
