JWT Generator

Published Updated

Sign a JWT with HS256, HS384 or HS512 from a header, a payload and a secret you type. Both JSON boxes are re-written without spaces before encoding, and a one-character secret, an alg of none or a payload that is not an object is signed with a warning under the token.

The three parts it builds

RFC 7519 defines a signed JWT as encoded header, payload and signature joined by dots, each in base64url with the trailing = signs removed. For the page's default boxes and the secret your-256-bit-secret, Google Chrome 156 gave:

PartBuilt fromResult
Header{"alg":"HS256","typ":"JWT"}eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Payload{"sub":"1234567890","name":"John Doe","iat":1516239022}eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
SignatureHMAC of the first two parts, joined by a dotSflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

The signature is 43, 64 or 86 characters long for HS256, HS384 and HS512. All three matched Node's crypto module byte for byte. Non-ASCII text is encoded as UTF-8 first, so "café 😀" in a payload decodes back to the same characters.

What the page does not check

It is a signing tool, not a validator, so some tokens it makes are poor ones.

  • A payload that is a JSON array or a bare number is signed, with a warning that other tools will not read it.
  • A header edited to say HS512 while HS256 is selected is signed with HS256.
  • A one-character secret works, with a warning, because RFC 7518 requires far more for these algorithms.
  • No expiry is set, so a token made here is valid for as long as the checker allows.

What the secret box hands to HMAC

The secret is used as typed: it is not trimmed and not decoded from Base64. TextEncoder turns it into UTF-8 bytes, and those bytes become the HMAC key through the raw import format of the Web Cryptography API. The warning under the token counts the same bytes. Measured in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app) with the default header and payload: the three gave identical tokens and warnings in every row, and each signature matched an HMAC computed over the same bytes with the crypto module of Node.js 22.23.1.

Secret typedUTF-8 bytesWarning under the token
your-256-bit-secret, the page's sample19HS256, HS384 and HS512 all warn: The secret is 19 bytes long
a, typed 32 times32None for HS256; HS384 and HS512 warn
b, typed 48 times48HS512 only
c, typed 64 times64None
é (U+00E9), typed 16 times32None for HS256; HS384 and HS512 warn
😀 (U+1F600), typed 8 times32None for HS256; HS384 and HS512 warn
secret, then secret with a space after it6, then 7All three warn; the two signatures differ
c2VjcmV0, which is secret written in Base648All three warn; the key is these 8 characters, not the word secret
café with a single é, then with e and a combining accent5, then 6All three warn; the two signatures differ

So a secret pasted with a trailing space, typed with a different accent form, or stored in Base64 by your server gives a different signature from one made with the server's own bytes.

Signing a test token

  1. Step 1

    Edit the header and payload

    Both boxes must hold valid JSON. Choosing another algorithm rewrites the header's alg only while the header is still the untouched default.

  2. Step 2

    Type the secret, then Generate JWT

    The button stays disabled until a secret is entered. The eye icon shows or hides the secret as you type it.

  3. Step 3

    Copy the token

    The token appears in a green box as three dot-separated parts. Changing any box, the secret or the algorithm clears it.

Checking the result

Paste the token into JWT Decoder to read the claims back. For a signature over arbitrary text rather than a token, HMAC Generator uses the same Web Crypto call and returns hex.

Signing questions

How long should the secret be?

RFC 7518 says the key must be at least as large as the hash output: 256 bits for HS256, 384 for HS384 and 512 for HS512. That is 32, 48 or 64 random bytes. The page still signs with a shorter secret, but shows an amber warning under the token that gives the length it found and the minimum.

Does it add iat or exp for me?

No. The payload is signed as typed. Both claims are NumericDate values, meaning seconds since 1 January 1970 UTC, so the sample iat of 1516239022 is 18 January 2018 at 01:30:22.

Can it make RS256, ES256 or an unsecured token?

No, only the three HMAC algorithms. Typing {"alg":"none"} in the header still appends a signature, while RFC 7519 gives an unsecured JWT an empty one, so the page shows a warning for it.

Why did a payload that is not an object still sign?

The page only checks that the text is valid JSON. The payloads [1,2] and 5 each produce a token, but a JWT claims set is a JSON object, so other tools will reject them. An amber warning under the token says so.

Why does the header lose its spacing and key order?

It is parsed and written back with JSON.stringify before encoding, so a header typed with spaces comes out compact. Keys keep the order you wrote, and extra fields such as kid are kept.

Is my secret sent anywhere?

No. The signature comes from the browser's Web Crypto API on this page; the secret is processed in your browser, and this page does not upload it. Even so, paste a throwaway secret here and never a production one.

Why does a 32-character secret get a warning with HS384 or HS512?

The warning compares the secret's UTF-8 bytes with the size of the hash: 32 bytes for HS256, 48 for HS384 and 64 for HS512. Thirty-two plain letters passed under HS256 and drew the warning under HS384 and HS512, in Chrome 157, Firefox 155 and the WebKit build alike.

Do accented letters or emoji make a secret longer?

In bytes, yes. é takes 2 bytes in UTF-8 and the 😀 emoji 4, so 16 é or 8 emoji make the 32 bytes HS256 asks for and get no warning. An é typed as e plus a combining accent takes 3 bytes, so café written that way signs differently from café with a single é.

Can I paste a secret that my server stores in Base64?

The page signs with the characters as typed and does not decode them. Pasting c2VjcmV0, the Base64 form of secret, signed with those 8 characters, and the signature differed from the one made with the word secret. A server that decodes its secret before signing will not get the same signature as a token made here from the encoded text.

Related Tools