格 千格 KiloCell

JWT Generating Full Guide: Issue, HS256 Signature, Keys and Interlock

Update 2026-08-09 About 14 minutes development tools How-to

When you write in, do API or build a controlled test, you're not really missing a "jsonwebtoken example" but rather a "jsonwebtoken" test. Header / Payload how to encode, what to sign, how to manage the key, how to self-check when issued Just one time. This Guide describes JWT generation from the issue perspective: how fields are selected, how HS256 signatures are calculated, how the HMAC generator is verified on a thousand cells in close loops with the decoding device, and gives the security boundaries of key, expiry and algorithm confusion - not rewriting the decoding guide.

Use tools immediately HMAC Generate - Local Calculating HS256 Signing Material
Open tool →

The core sentence.

Generate JWT = write a clear statement + sign "header.payload" with the correct algorithm; The signature is protected against tampering and is not confidential.

Main link: used HMAC Generators Understand and calculate HMAC-SHA256 signature material, for JWT decoder Read back/payload and do HS256. Official issuance in the business system should remain in the service repository; This guide addresses "You know what you're signing, how you're checking, where you're going to roll over."

1. Issuance perspective: what are the three paragraphs each writing?

Tight sequences remain:

base64url(header).base64url(payload).base64url(signature)

Unlike "code only", you must decide on each paragraph at your own initiative.

Header: The algorithm contract, not the decoration.

Header:

{
  "alg": "HS256",
  "typ": "JWT"
}
Fields What's the order when you sign it? Post-generation consequences
alg Same as key type, checker configuration Write HS256 Instead, you use the RSA private key, or write it. RS256 But with a symmetric key, the other side refused.
typ Most scenes are fixed JWT (b) A few gateways will be verified; Don't write it like that. token
kid Identification of key version on key rotation Check the signature party to press kid (a) Select key; Missing default key or failed

Don't do it."To be convenient" on the client alg Replace with none or allow the caller to specify an algorithm. The algorithms often confuse the root cause of the attack: the signing firm trusted Token's self-reported. alg, the wrong type of key was used.

Payload: Only "public + expired" statements

{
  "sub": "u_1024",
  "iss": "https://auth.example.com",
  "aud": "api.example.com",
  "iat": 1723180800,
  "exp": 1723184400,
  "scope": "read:orders",
  "role": "ops"
}

List of issues (in order of priority):

  1. exp: Almost all of Token production should be available; The U.S. calls are much safer (5-15 minutes) than "one year without expiry".
  2. iat / nbfThe following video shows the number of people who have been killed by the police:nbf The current time is more than "not yet in effect".
  3. sub: stable master marking; No SLB is explicitly used as a sole basis unless the product expressly requires and is acceptable for disclosure.
  4. iss / audMulti-service, multi-client, write-in to avoid Token being used in a different API.
  5. Operations:scope、tenant_id、role etc.; Type is stable (string vs numbers, single values vs array).

Ban on writing: Password, refreshing tokens, complete bank cards, permanent API Secret, direct access points. Payload can be decoded by any holder, Base64URL - this is a format design, not an omission.

Signature: "Keyprints" for the first two paragraphs

For HS256, the normative meaning is:

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

Then we'll do the binary result Base64URL, get the third paragraph. The three most easily wrong things to do when they are generated:

  • Signing input missing the middle Node.or sign the whole JWT again;
  • Standard Base64 for Header/Payload + / and =(i) The following:
  • The key is changed, the UTF-8/UTF-16 is mixed, or the "example key" and "real key for environmental variables" are mixed.

2. Pre-generation type: HS256 or asymmetric

Requirements A more appropriate choice. Reason
Single backend, key only at serviceend HS256 / HS384 / HS512 (a) Making it simple; Check and issue the common key
All the micro-services are checked, only the certification center can sign. RS256 / ES256 etc. Public key is distributed, private key is not issued
Browser/Movingend "issuance" to home API Usually. I shouldn't. Once the key is on the client, it's open.
I just want to read it locally, Token. Decoding is fine. It doesn't have to be generated. See JWT decoded guide
Webbook / Original Document Integrity HMAC itself, not necessarily JWT Use HMAC Generators More directly.

The generation of landable sites is practiced to HS256 Main: HMAC generator is responsible for "Key Summary" and JWT decoding is responsible for "Strike + Optional HS256 Signing". RS256 Private key calculations do not work the whole process - production is a mature library - in the safety model of the browser tool.

Key length experience (symmetry):

  • HS256: Key entropy not lower than 256 bit (32 bytes random) secret、123456, the project name is the key;
  • Rotation: new key online kid (b) Distinction; Old Token is in exp The old key may still be used to verify the internal contents and the natural phase-out after expiry;
  • Storage: Environmental variable / key hosting, not in Git, not in front-end package, not in guide screenshot.

3. Base64URL and "signatureable string"

Half of the generation failures are in code, not code.

Steps The right way. Common error methods
JSON Sequencing Keys are fixed, no extra spaces (or canonical as agreed) This is a beautiful indentation, and the compression is causing a discrepancy in the signature input.
Coding Base64URL, get rid of it. = Fill Normal Base64, or manual replacement only partial characters
Collapse encodedHeader + "." + encodedPayload Direct HMAC in commas, spaces, or to the original JSON
Sign Output Binary → Base64URL Output hex when JWT third part

Available Base64 tools Understand coding differences, but Dismantling and HS256 for whole JWT I should still be back. JWT decoder。 Payload, when it's big, use it first. JSON Format proofread fields, encoded token.

Minimum handshake example (structure only, key is for presentation):

header  = {"alg":"HS256","typ":"JWT"}
payload = {"sub":"demo","exp":1893456000}
signing_input = base64url(header) + "." + base64url(payload)
signature     = base64url( HMAC_SHA256(signing_input, "demo-only-secret") )
jwt           = signing_input + "." + signature

I'll get it. jwt Paste decoding device: should be visible sub/exp; Fill with the same in the check box demo-only-secret and when the algorithm HS256 is, the signature should be shown to be valid. One byte is changed and the approval should fail — this is the definition of “success generation”, not “the string looks like three segments”.

4. Walking through KiloCell of cells to "generate materials and self-censorship"

The warehouse currently does not have a single "one-key form out of JWT" page. Generate Practice By HMAC Generator + JWT Decodingr (and Base64/ JSON) Composition. It's more efficient than half-posting Token in the chat.

Preparation of statements (recommendations first JSON tool)

  1. Open JSON FormatWrite Header and Payload separately, confirm legal JSON.
  2. - Put it on. exp Written sec Level Unix time; You can observe both states as "unexpired / expired" with short expiry.
  3. The business field only retains the minimum set required for the connection, avoiding the need to plug dozens of claires at a time.

Getting signed input

  1. Header and Payload are separate Base64URLs (no fill).
  2. In English, in a single dot. signing_input。
  3. The string of this step must be the first two paragraphs of the final JWT Same by characterOtherwise, HMAC will be wrong.

C. Signing material using HMAC generator

  1. Open HMAC Generators。
  2. Algorithms and Header alg corresponds to HMAC-SHA256 (or the SHA variant that you agreed in your document).
  3. Key Fill in shared keys;Data Complete signing_input(Two paragraphs + midpoint), not just Payload.
  4. Confirm output code after generation: JWT 3 needs Base64URL Form. If the tool is defaulting on hex/ Normal Base64, convert the library document you use or complete the final assembly in the service repository that supports JWT.
  5. Assembly:jwt = signing_input + "." + signature_base64url。

D. Close the ring with the decodor immediately

  1. Open JWT decoder。
  2. Just paste Token Body, don't bring Bearer 。
  3. Checking Header's algPayload's. exp Local time and business field.
  4. Fill in "Pertify Signature" Same Key(HS256 path only): this round is established by passing; Failure returns to B/C check encoded and key instead of changing business interfaces first.
  5. The two Payloads are to be copied to the JSON tool for a structured comparison when comparing the two issuance differences.

Tool boundary (avoid expected misalignment)

  • HMAC Generators: General message authentication codes; Helps you understand and calculate the "key + message summary" or other non-JWT scenes like Webbook signature.
  • JWT decoding device: Three paragraphs.exp/iat Readable, Optional HS256 (b) Signing; Not responsible for RSA private key issue.
  • Hash Generators: (a) A key summary for the document/text fingerprint;couldn'tOther Organiser Hash Guide)。
  • Officially issued: An eco-ecological JWT library such as Node / Java / Go (processing encoding, time, key and anti-mixing configuration); Browser small tools are used for teaching, connecting and typifying, not IdP.

5. Common rollovers and comparisons after issuance

phenomena More likely to be a side cause Processing
Decoding succeeded but the signature failed Key incoherence, signing input missing, Base64 variant error, key tail space Fixed a "key + signing input" comparison; Use decoding device HS256 to verify location
Service 401 "signature invalid" Another set of Secrets was used in the environment; Or, Header. alg Not in line with library configuration Print key fingerprints (Hashi) rather than explicit for the issuing and signing environment; Check alg
It just expired. exp Misunderstanding in milliseconds, or server UTC/local time zone (a) Uniform seconds; (b) The decoding device to read local reading times; Packaging NTP
nbf It leads to occasional failure. Advance Token or clock callback Leave seconds for issuance, locksk, or document to specify allowed offsets
Frontend "change role is still old permission" Changed local decoded results without resigned with key Token must be resigned; Payload can still be used if it is changed, which means that the service has not signed
Gateway reception, business denial aud/iss/ Customized claim type is not correct (a) Write the contract of claim as a table at the time of generation; View type with JSON tool
Algorithm is RS256, local HS checkout hint not supported Asymmetrical Token Decoded to read the declaration; Check to remove public key and service logs
Token with line breaks/spaces Wrap lines when copying from log or mail Keep three single lines for generation and paste

6. Real work scene

Scenario A: Backend not ready. Frontend to pre-empt the false login with access.

Make a short expired one.role/scope Full HS256 Token, written in local development gateway or mock. Use the decoding to confirm the field and then let the front end be true. Authorization Head.Keys are only left locally .env, the advance of shared front-end warehouses is prohibited. Fake Token iss Recommendation dev- Prefixes, avoid prefixing.

Scret: Two environments are different, and the connection "same user" is just one side away.

Don't start with business code. Sign one each of the same Payload, decoded against whether Header is HS256, then sign with their respective environment keys on the decoder. If A key can verify A votes, cannot check B tickets, the problem is distributed in the key and not on the user chart.

C: Migration Session → JWT, with the "minimal collection"

The following is a list of the most important topics that are being discussed:sub、exp、iat、sid(session version)auth_time。 Each example is issued by table, using an decoder as a receiving and inspection tool: the creation of scripts for missing fields has failed. It is more time-consuming than the 403 log inverted field.

Scene D: Suspected of forgery Token

Take a line-on-line (or audit) Token, decode it. alg and kid。 If alg Yes none or not in accordance with the document, as per the incident. HS256 Signing with current key: Failure indicates that the system is not issued; And we'll check it out. exp With permission to claim is not used for business. The side protections to be generated are:Private keys/keys are not issued, and the caller decides against the alg.

7. Security and key: Write in process when generated

  • Key for password: Sufficient length and randomness; Rotation kid; Disclosure is the rotation and, where appropriate, cancellation of the unexpired ticket.
  • Short Expiry + Refresh token: Visit Token minutes — hour; Refresh Token Storage Service to cancel storage, not just for excessive length exp。
  • Generate environmental isolation: Develop/ pre-issue/ manufacture key separation; Prohibits the production of keys to appear in presentations.
  • Transfer: Only HTTPS; Do not use the complete Token as URL long-term query parameter (logs and reper will leak).
  • Log: Just call. jti Or several before and after Token; Full JWT log entry is the same as a leak.
  • Library Configuration: A list of algorithms that are allowed to write a death by the approving port; Close none; HS and RS do not mix the "Mixable Signing" function.
  • Browser tool: Thousands of local processing machines are still not posted on shared screens or recorded presentations for high-capacity production tickets.

FAQ

There is no separate JWT generator page. Can you practice generation?

Yes. The essence of the creation is the code + HMAC (symmetry) or private key signature (asymmetric). Thousands of cells overwhelm symmetric signature materials with HMAC generators and JWT decoding machines for results acceptance. The production environment should be changed to the service JWT library to complete the encoding and signature once and avoid errors in hand rubs.

Is the signature encrypted? Is it the only server that can see Payload?

Nope. The signature certificate "the key holder accepts the above and the content remains unchanged". Header and Payload are still decodeable. The source of the video is HTTPS and "Don't put the secret in Payload", not JWT, which is a mess.

May HS256 key be written at the front end?

No, I can't. The key that you can get at the front end is the public key, and anyone can sign "Administrator" Token. The browser should only hold Token (or adopt a secure BFF mode) that has been issued by the service.

Why can't I get the tickets signed online?

Item by item:alg, key bytes, Base64URL to fill, signing input to include dot marks, time claim to seconds, library to reject the algorithm you use. Use the local decodator to make the middle: ensure "self-signed self-check" before docking to the official library.

How long should it be?

Press exposure: API uses shorter access to Token to update; Read only internally for a slightly longer period, but should be available for rotation. The joint example is 5-15 minutes to facilitate the presentation of expired and to avoid the misuse of the test ticket for long periods of time.

Could you sign with MD5 or n nudity SHA256 when JWT?

Could not close temporary folder: %s JWT's HS* is HMAC (a) Groups; Naked Hash had no key to protect against forgery. Use the Hash tool when you need a key fingerprint, use the HMAC or complete JWT library when you need a key integrity.

Do you want to change 'jti ' every time you're produced?

If you re-test, one-time ticket or blacklist, you need the only one. jti。 Short-term expired visitor tickets are optional, but in the audit scenario jti It's working.

What's the difference between hand rubs and production banks?

(a) Hand rubs to help understand byte level agreements; The production bank handles algorithms with security defaults, clocks, key formats and anti-mistols. The upper path should be based on the library, and the tool chain should be used for teaching and trouble-positioning.

Continue reading

The "HMAC decoded signature" is done locally with a demonstration key. Confirms that the same contract of claim is entered into the service-end issuance code after you have made contact. When you are wrong, you have to set the key to signing input instead of changing the business and gateway at the same time.