Skip to content

JWT Encoder

Sign a JSON payload with HMAC SHA-256. The page always sets the algorithm to HS256. It does not send the token anywhere.

Result

Enter a payload and a secret

How to Use

  1. 1 Enter a JSON object and a secret.
  2. 2 Choose Sign the token.
  3. 3 Copy the three-part token. The page does not send it.

Example Output

  • A payload of {"sub":"123"} with a secret you type.

About This Tool

The header and the payload are base64url JSON. The third part is the HMAC of those two parts.

Using the JWT Encoder

The JWT Encoder signs a JSON object with HMAC SHA-256. The payload starts as {"sub":"1234567890","name":"Ada","iat":1516239022}. The secret starts as secret. Choose Sign the token. The label above the headline reads Algorithm. The headline is HS256. The algorithm line is HS256. The result text is the token. The algorithm is always HS256. The page does not send the token.

The token has three parts separated by dots. The first part is the header, with alg set to HS256 and typ set to JWT. The second part is the payload you typed. The third part is the HMAC SHA-256 signature of the first two parts, using the secret. For this payload and the secret secret, the token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The full token is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFkYSIsImlhdCI6MTUxNjIzOTAyMn0.3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. Sign the same payload and secret again and the token matches.

The steps under the result say to set the header algorithm to HS256, encode the header and the payload as base64url, and append the HMAC SHA-256 signature. There is no field for a different algorithm. The headline stays HS256 for every successful run. A JSON array is rejected. A payload of [1,2] makes the headline read Payload must be a JSON object. The algorithm line is cleared, because the token was not signed.

The payload must be from 1 to 4000 characters, and it must decode as a JSON object. An empty payload says Payload must be from 1 to 4000 characters. A payload longer than 4000 characters uses that same message. The secret must be from 1 to 200 characters. An empty secret says Enter a secret from 1 to 200 characters. A secret longer than 200 characters uses that same message. The page does not send the token to a server. The token stays in the result.

The header is the same on every successful token this page builds, because alg is HS256 and typ is JWT. The first part of the sample token is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. That part does not contain the name Ada or the secret. The middle part is the payload. The last part is the signature. For the secret secret, that signature is 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The header and the payload are base64url JSON. The signature is base64url of the HMAC, with padding removed. The page does not send any of those parts.

iat in the sample is the number 1516239022, not a string in quotes. sub and name are strings. The page signs the object you typed. It does not check that iat is a clock reading, and it does not reject the name Ada. Change the name and the middle part changes, and the signature changes with it. The headline stays HS256. Restore the name Ada and the secret secret, and the token again ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. A JSON array cannot take that path. [1,2] stops at Payload must be a JSON object. The algorithm line stays empty until a later run succeeds.

Copy result copies the token, not the headline HS256. For the starting fields the copy ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. Reset returns the payload and the secret to the starting values, and the headline to Enter a payload and a secret. Copy the token before you reset. Change the secret and the signature changes. Restore secret and the token again ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04.

What the Token Contains

The token is three base64url parts. The header is the JSON object with alg set to HS256 and typ set to JWT. The payload is the object you typed. For the sample, that object has sub set to 1234567890, name set to Ada, and iat set to 1516239022. The signature is the HMAC SHA-256 of the header and the payload, joined by a dot, keyed with the secret. The headline is HS256. The algorithm line is HS256. The result text is the whole token.

The page does not send the token. Signing shows the three parts on this page. It does not post them, store them, or call an address. The same payload and the same secret rebuild the same token. With the secret secret, that token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. Read the headline as the algorithm. Read the result text as the token. Count the dots if you want to confirm the shape. Two dots means three parts. The sample has that shape, and the last part is 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The first part stays eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 while the header stays HS256 and JWT. A different payload changes the middle and the signature. It does not change the headline.

How the Sample Payload Is Signed

The page checks that the payload is a JSON object and that the secret is within its length. It builds the header with alg HS256 and typ JWT. It encodes the header and the payload as base64url. It computes the HMAC SHA-256 of those two parts with the secret, and it appends that signature as the third part. For {"sub":"1234567890","name":"Ada","iat":1516239022} and the secret secret, the third part is 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The headline is HS256. The page does not send the token.

Reading a token is a different pass, and it does not prove the signature. The JWT Decoder decodes the header and the payload. The page does not check the signature, so a decoded payload is not proof that the token is genuine. A token needs two dots and three parts. The signature line there reads Not checked. Use it when you want to read the JSON. Use this page when you want to sign an object with HS256. The decoder does not create the sample signature.

What the Page Refuses to Sign

A JSON array is rejected with Payload must be a JSON object. [1,2] is an array, so the headline is that message and no token is shown. A JSON string, a number, or a broken fragment fails the same way, because the value is not an object. An empty payload fails earlier, with Payload must be from 1 to 4000 characters. The secret is separate. A blank secret says Enter a secret from 1 to 200 characters. The page does not invent a secret for you.

The algorithm does not change when the payload changes. There is no control that sets alg to another name. The header on a successful run is HS256. The headline is HS256. The page does not send the token after it is built. If you need the token somewhere else, copy it yourself. The result on this page is the end of the signing step. Copy the token from the result text if you need it in your own notes. The headline HS256 is the algorithm label, and it is shorter than the token. The token is the long three-part value. For the sample, judge the copy by the ending 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04 and by the two dots. The page will build that value again from the same payload and the same secret. It will not send it.

The Sample Object and the Secret secret

Leave the payload as {"sub":"1234567890","name":"Ada","iat":1516239022} and the secret as secret. Choose Sign the token. The headline is HS256. The algorithm line is HS256. The token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. Sign again. The token matches. Replace the payload with [1,2]. The headline reads Payload must be a JSON object. Restore the sample object and the secret secret. The headline returns to HS256, and the token again ends with that signature.

A hash of plain text has no header and no secret. The SHA-256 Generator hashes the text you type with SHA-256. hello is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. The result is 64 lowercase hex characters. That page does not store the text. Use it when you want the digest of a string. Use this page when you want an HS256 token from a JSON object and a secret. The hello digest is not the sample signature, and it is not a three-part token.

Bounds on the Payload and the Secret

The payload must be from 1 to 4000 characters, and after that length check it must be a JSON object. Empty text says Payload must be from 1 to 4000 characters. Text past 4000 characters uses the same message. An array, including [1,2], says Payload must be a JSON object. The secret must be from 1 to 200 characters. Empty text and text past 200 characters say Enter a secret from 1 to 200 characters. The lines are cleared when a field fails, and the headline is the message rather than HS256.

A successful secret can include spaces if you typed them, because the check is the length after the field is read, and a secret that trims to empty is rejected. The sample secret is the word secret, with no extra space. The payload sample is one object. The page does not send either value. The token in the result is the signed output, and the headline remains HS256. A secret of only spaces is rejected, because the trimmed secret is empty, and the message is Enter a secret from 1 to 200 characters. The sample secret is the five letters secret, with no space before or after. The payload sample fits well inside 4000 characters. You do not need a longer object to see the sample signature.

Tokens People Expect From the Wrong Inputs

A common miss is to paste [1,2] and expect a token. A JSON array is rejected with Payload must be a JSON object. Another miss is to look for a way to choose an algorithm other than HS256. The algorithm is always HS256. The headline says so. Another miss is to treat the headline as the token. The headline is HS256. The token is the result text, and it ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04 for the sample. Another miss is to think the page sent the token. The page does not send the token. Another miss is to change the secret and expect the same ending. The signature uses the secret you typed.

A shorter checksum is a different digest. The MD5 Hash Generator hashes the text you type with MD5. hello is 5d41402abc4b2a76b9719d911017c592. That page does not store the text. MD5 is a checksum here, not a password store. Use it when you want that 32 character checksum. Use this page when you want an HS256 token. The hello checksum is not the signature 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04.

Sign the Sample, Then Reject an Array

Enter the payload {"sub":"1234567890","name":"Ada","iat":1516239022} and the secret secret. Sign the token. The headline is HS256. Confirm the token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. Change the secret to another word within 200 characters and sign again. The headline stays HS256, and the ending changes. Restore the secret secret and confirm the sample ending returns. The algorithm line should read HS256 on each successful sign.

Replace the payload with [1,2]. The headline reads Payload must be a JSON object. Clear the payload. The headline reads Payload must be from 1 to 4000 characters. Restore the sample object. Clear the secret. The headline reads Enter a secret from 1 to 200 characters. Restore secret. Confirm the headline is HS256 and the token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The page does not send that token.

Keeping the Token With the Payload and the Secret

Copy the token. For the sample it ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04, and the headline is HS256. Write the payload and the secret beside that copy if you need to sign it again later. The page does not store the run, and it does not send the token. A note that says only HS256 can be any signed object. The ending identifies this payload with this secret. Change either one and the ending changes. Keep the token that matches the fields you used.

A readable payload is a different record from the signed token. The JSON Prettifier formats JSON with line breaks and four-space indentation. {"a":1} becomes a readable object that still contains a and 1. That page does not fetch JSON. Use it when you want the object indented. Use this page when you want the object signed as HS256. The indented object is not a three-part token, and the prettifier does not add the signature.

An HS256 Token From the Object and the Secret

The headline answers which algorithm signed the object. It is HS256, because the algorithm is always HS256. The result text is the token. For {"sub":"1234567890","name":"Ada","iat":1516239022} and the secret secret, the token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. A JSON array is rejected with Payload must be a JSON object. The page does not send the token. Those outcomes come from the payload and the secret you typed.

Checking the Ending Against the Sample

Use the sample payload and the secret secret. Sign the token. The headline should be HS256. The token should end with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The token should contain two dots, so it has three parts. Replace the payload with [1,2]. The headline should read Payload must be a JSON object, and the token should be gone. An empty secret should read Enter a secret from 1 to 200 characters. The page does not send the token on the successful run. The label above a successful headline reads Algorithm.

Splitting an address is a different three-part idea. The URL Parser splits an http or https URL into its parts. https://www.nimbtools.com/path?a=1#top has the host www.nimbtools.com. That page does not open the URL. Use it when the text is an http or https address. Use this page when the text is a JSON object and a secret and you want an HS256 token. The host www.nimbtools.com is not the signature, and this page does not send the token to that host or to any other address.

Frequently Asked Questions

What do the sample payload and the secret secret return?

The headline is HS256. The token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04. The payload is {"sub":"1234567890","name":"Ada","iat":1516239022}. The algorithm is always HS256. The page does not send the token.

What are the three parts?

The header is base64url JSON with alg HS256 and typ JWT. The payload is the object you typed, also base64url. The third part is the HMAC SHA-256 signature of the first two parts, using the secret. The sample signature is 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04.

What does a JSON array do?

It is rejected. A payload of [1,2] makes the headline read Payload must be a JSON object. No token is shown. The payload has to be a JSON object, such as the sample with sub, name, and iat.

Can the algorithm be something other than HS256?

No. The algorithm is always HS256. The headline on a successful run is HS256. There is no field for another algorithm. The header sets alg to HS256.

Does the page send the token?

No. The page does not send the token. The token is shown in the result so you can copy it. Signing does not post the token to an address.

How long can the payload and the secret be?

The payload must be from 1 to 4000 characters. The secret must be from 1 to 200 characters. An empty payload uses the payload length message. An empty secret says Enter a secret from 1 to 200 characters.

Is the headline the token?

No. The headline is HS256. The token is the result text. Copy result copies the token. For the sample, that token ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04.

What does Reset restore?

It restores the sample payload, the secret secret, and the headline to Enter a payload and a secret. Copy the token first if you want to keep the signature that ends with 3o_ti1Cj-WEtqilw-c6CrPK7JxFXqcz1SN_CwMkbe04.