Signing a JWT and Understanding What You Prove
By toolbelt maintainers ·
Updated
Testing auth code needs a valid token. Generating one by hand is error-prone, and getting the signature wrong teaches you nothing about why.
What is this tool?
Signing a JWT means hashing the header and payload with a secret and appending the result. The signature proves the token was produced by someone holding that secret. It does not hide the contents.
How it works
The header names the algorithm, the payload holds your claims, and together they form the signing input. I hash that with HMAC using your secret through the browser crypto API and append the result as the third segment.
Example
Header: {"alg":"HS256","typ":"JWT"}
Payload: {"sub":"123","name":"Ada"}
Result:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjMiLCJuYW1lIjoiQWRhIn0.<signature>When to use it
Producing a token for a local dev server. Checking that your verification code rejects a tampered payload. Reproducing the exact token from a failing test so you can compare it byte for byte.
Optimization Tips
Never paste a production secret into a web tool you did not read the code of. HS256 uses one secret for both signing and verifying, so the secret is the whole security model. Where only public verification matters, use RS256 and keep the private key off the client entirely.
Frequently Asked Questions
Can I use RS256 here?
Does signing encrypt the payload?
Should I set exp?
Why does my server reject the signature?
Related tools
- Base64 Encoder/DecoderEncode and decode Base64 strings safely. Supports full UTF-8 characters, emojis, and binary data. Ideal for debugging data URLs or API authentication headers.
- URL Encoder/DecoderPercent-encode and decode URLs. Safely escape query parameters, path segments, or full URLs to ensure they are valid and won't break during browser routing or API requests.
- JWT DecoderDecode JSON Web Tokens to inspect the header and payload. Debug authentication flows, check expiration times, and view user roles without verifying the signature.
- Env ValidatorCheck a .env file for duplicate keys, unclosed quotes, unquoted spaces and placeholder secrets before they break a deploy. Reports the line number of each problem.