HandyBench

JWT Encoder

Sign JWTs with an HMAC secret.

Signing runs entirely in your browser with the Web Crypto API. Don’t paste production secrets into any web tool.

How to use the JWT Encoder

  1. 1 Pick the HMAC algorithm (HS256, HS384 or HS512).
  2. 2 Enter your secret and edit the JSON payload.
  3. 3 Click Sign token and copy the resulting JWT.

What signing a JWT involves

A signed JWT is a JSON Web Signature (RFC 7515) whose payload is the claims set from RFC 7519. The encoder builds it in three steps. It writes the header {"alg":"HS256","typ":"JWT"}, with whichever algorithm you picked. It re-serialises your payload with JSON.stringify, which removes whitespace and keeps key order. It base64url-encodes both and joins them with a dot to form the signing input. Then the Web Crypto API computes an HMAC over that string using your secret and appends the result as the third segment.

The secret is converted to bytes as plain UTF-8 text. It is not base64-decoded first, so a secret that another system stores in base64 must be decoded before you paste it, or the signatures will not match.

Algorithms offered

NameHash used by HMACSignature length (base64url)
HS256SHA-25643 characters
HS384SHA-38464 characters
HS512SHA-51286 characters

These are the symmetric algorithms of RFC 7518 section 3.2. The same secret both signs and verifies, so there are no RSA or ECDSA options, which would need a private key. RFC 7518 says the key should be at least as long as the hash output, which is 32 bytes for HS256. The tool does not enforce that, so a short secret signs without complaint.

Worked example

Signing {"sub":"1234567890","name":"Jane Doe","iat":1700000000} with HS256 and the default secret your-256-bit-secret yields:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkphbmUgRG9lIiwiaWF0IjoxNzAwMDAwMDAwfQ.
G2Fn2qE65tMTYs_mW1CVKaLoDWR0nkWkyL0H6Dc12IY

(shown on three lines; the real token has no line breaks). The iat value 1700000000 is 22:13:20 UTC on 14 November 2023. Recomputing the HMAC-SHA256 of the first two segments with another library gives the same final segment.

Security notes

  • A shared secret is a signing key. Anyone who knows it can mint tokens your server will accept. Use throwaway secrets for tests and fixtures, never the production value, and treat anything typed into a web page as exposed.
  • Nothing is added for you. The payload is signed exactly as typed. Set exp, iat and aud yourself, in Unix seconds.
  • Signing is not encryption. The claims stay readable by anyone holding the token.
  • Servers should pin the accepted algorithm instead of trusting the header's alg, which prevents downgrade tricks such as alg: none.

To read a token you already have, use the JWT decoder. The hash generator shows the plain digests that HMAC builds on.

Examples

  • ▸ HS256 with secret "your-256-bit-secret" and payload {"sub":"1234567890","name":"Jane Doe","iat":1700000000}.
  • ▸ A test token for an API in development, signed with a throwaway secret.

Frequently asked questions

Is the signing secret sent anywhere?

No. The token is signed locally with the Web Crypto API, so your secret never leaves the browser. Still, avoid pasting real production secrets into any online tool.

How is this different from a JWT decoder?

A decoder only reads an existing token’s header and payload. This encoder builds a new token and signs it with your secret so the signature verifies.

Which algorithms are supported?

Symmetric HMAC algorithms: HS256, HS384 and HS512. Asymmetric algorithms (RS/ES) require a private key and are out of scope for a client-side tool.

Does the tool add exp or iat automatically?

No. The payload is signed exactly as you type it. Add exp, iat and any other claims yourself, as Unix timestamps in seconds.

Should my secret be base64-encoded?

The secret you type is used as plain UTF-8 text, not base64-decoded. If another system stores its key in base64, decode it first or the signature will not match what that system computes.

How long should an HS256 secret be?

RFC 7518 requires a key at least as long as the hash output, which is 32 bytes for HS256. The tool will sign with a shorter secret without warning, but a short secret is easy to brute-force.