Skip to content

JWT encoder and signer

Write a header and claims, pick HS256, HS384 or HS512, and sign them with a shared secret to get a test JWT. The token updates as you type.

Runs in your browser. Nothing you paste is sent to us.

Header and claims

Algorithm

Sample claims for the made-up realm acme. Times are Unix seconds.

Signed token

A sample secret is filled in. Use a throwaway one, not a secret from a live system.

How the secret is written. Base64 and hex are decoded to bytes before signing.

JWT
 
For testing only. Signing happens in your browser; never paste a production secret into a web page.

How to use it

  1. Pick the algorithm. The header’s alg changes to match.
  2. Edit the claims. Use the buttons to set iat to now and exp a few minutes ahead.
  3. Enter a test secret and say whether it is text, Base64, Base64url or hex.
  4. Copy the signed token and send it to the service you are testing.

What to know

An HMAC-signed JWT is checked with the same secret that signed it. That makes it handy for tests and for services you control on both ends.

RFC 7518 asks for a secret at least as long as the hash: 32 bytes for HS256, 48 for HS384 and 64 for HS512. The tool warns when yours is shorter.

Keycloak signs access and ID tokens with RS256 by default, using a key pair. To create a token that passes as a realm’s own, you would need the realm’s private key, which never leaves Keycloak. Use this tool for test tokens only.

Why build a JWT by hand

Most of the time an identity provider creates your tokens. But when you test an API, a gateway rule or a library, you often need a token with exact claims: one that expired a minute ago, one with a wrong audience, one with a role your test user does not have.

Asking a real identity provider for such a token is slow or impossible. Building one yourself, signed with a test secret your service also knows, takes seconds. This tool does that with HMAC: HS256, HS384 or HS512.

How an HMAC-signed JWT is made

RFC 7515 (JSON Web Signature) defines the steps. The header and payload are serialized as JSON, encoded with Base64url, and joined with a dot. That string is the signing input. The signature is an HMAC of the signing input, keyed with the shared secret, and it is appended after a second dot.

HS256 in three lines
signing_input = base64url(header_json) + "." + base64url(payload_json)
signature     = HMAC-SHA256(secret, signing_input)
token         = signing_input + "." + base64url(signature)

Because the same secret creates and checks the signature, anyone who can verify an HS256 token can also create one. That is fine when both ends are yours, and a problem when many services verify the same tokens.

HS256, HS384 and HS512

AlgorithmHashMinimum secret (RFC 7518)
HS256SHA-25632 bytes
HS384SHA-38448 bytes
HS512SHA-51264 bytes

RFC 7518 requires a key at least as long as the hash output. A short or guessable secret can be found offline by anyone who holds one token, so the tool warns you when yours is too short.

What this tool does

  • Signs the header and payload you write with HS256, HS384 or HS512, live as you type.
  • Reads the secret as text, Base64, Base64url or hex, so it matches how your service stores it.
  • Sets iat to now and exp a few minutes or an hour ahead with one click.
  • Warns when the secret is shorter than RFC 7518 asks for.
  • Writes the JSON compactly before encoding, so the token is as short as possible.

It does not sign with RSA or EC keys, and it cannot produce a token that a Keycloak realm’s clients will accept as the realm’s own. That would need the realm’s private key, which never leaves Keycloak.

How to build a test token

  1. Pick HS256, HS384 or HS512. The header’s alg changes to match.
  2. Edit the payload. Keep the claims your service checks: usually iss, aud, sub, exp and iat.
  3. Click the button to set iat to now and exp a few minutes later, or type the times yourself.
  4. Enter the same secret your service uses in its test configuration, and pick the format it is written in.
  5. Copy the token and send it as Authorization: Bearer <token>.

Choosing claims for a useful test

A good test token looks like a real one in every way except the one thing you are testing. Start from a token your issuer really produced; decode it with the JWT decoder and copy its payload here.

Times

Times are Unix seconds. To test expiry handling, set exp a few seconds in the past. To test clock-skew tolerance, set nbf or iat slightly in the future. The Unix timestamp converter turns dates into seconds.

Issuer and audience

To test that your API rejects foreign tokens, change iss to another realm, or set aud to another client. A correct API rejects both even when the signature is valid.

Roles

If your API reads Keycloak-style roles, add realm_access: { roles: [...] } and resource_access: { "<client-id>": { roles: [...] } }. Removing a role is the quickest way to test a 403 path.

Where HMAC tokens are used with Keycloak

Keycloak signs access and ID tokens with RS256 by default, using the realm’s RSA key pair. Clients verify them with the public keys from /realms/<realm>/protocol/openid-connect/certs. You cannot reproduce those signatures here, and you should not need to.

HMAC does appear in Keycloak in other places. A client can authenticate to the token endpoint with “Signed JWT with Client Secret” (client_secret_jwt), which is a short JWT signed with HMAC using the client secret. The setting is on the client’s Credentials tab, under Client Authenticator.

Keycloak also keeps HMAC keys in each realm for tokens only Keycloak itself checks, such as refresh tokens. Those secrets are not shown or published, so treat such tokens as opaque.

Use cases

Unit and integration tests

Configure your service under test to accept HS256 with a test secret, then generate tokens for each case: valid, expired, wrong audience, missing role. Keep the generated tokens in fixtures, or generate them in the test with the same steps.

Checking a gateway or proxy rule

Many gateways can validate HMAC-signed JWTs with a shared secret. A hand-made token tells you quickly whether a rule reads the claim you think it reads.

Learning how JWTs work

Change one character in the payload and watch the signature change completely. Then paste the token into the signature verifier with a different secret and see it fail.

Common mistakes

  • Secret format mismatch: your service may store the secret as Base64 while you typed it as text. The bytes differ, so the signature differs.
  • Times in milliseconds: Date.now() returns milliseconds. JWT times are seconds, so divide by 1000.
  • Pretty-printed JSON in the signing input: harmless, but the token becomes longer. This tool always signs compact JSON.
  • Using alg: none to skip signing: a correct verifier rejects such tokens, so the test proves nothing.
  • Reusing a production secret for tests: anyone with the test token and the code can then forge production tokens.

Doing the same in code

For automated tests, generate tokens in code instead of copying them from a page. Every JWT library can sign with HMAC.

Signing an HS256 test token in Node.js
// Node.js, with the built-in crypto module only
const b64 = (v) => Buffer.from(JSON.stringify(v)).toString('base64url');
const input = b64({ alg: 'HS256', typ: 'JWT' }) + '.' + b64(claims);
const sig = crypto.createHmac('sha256', secret).update(input).digest('base64url');
const token = input + '.' + sig;

Compare a token made in code with one made here, using the same header, claims and secret. They should be identical, which is a quick way to check your test helper.

Security notes and limits

Signing happens in your browser with Web Crypto. Nothing is sent to us. Even so, a web page is the wrong place for a production secret; use a throwaway one made for tests.

An HMAC secret should be random bytes, not a word or a phrase. Generate one with the client secret generator or the JWK generator set to a symmetric key.

Tokens made here are for testing. Production tokens should come from your identity provider.

Best practices for HMAC-signed tokens

  • Use at least 32 random bytes for HS256, and more for HS384 and HS512.
  • Pin the algorithm in your verifier. Never let the token’s alg decide which algorithm to use.
  • Prefer RS256 or ES256 when more than one service verifies the tokens.
  • Rotate secrets on a schedule, and support two at once during the change.

Keep test secrets in test configuration only, and give them names that make their purpose obvious, so nobody copies one into production by mistake.

Questions

Frequently asked questions

Can I sign a token with RS256 here?

No. This tool signs with a shared secret only (HS256, HS384, HS512). For RS256 or ES256, generate a key pair with the JWK generator and sign with a library in your own code.

How long should an HS256 secret be?

At least 32 bytes, which is the size of the SHA-256 output (RFC 7518). Use random bytes from a secure generator, not a password or a phrase.

Why does my service reject the token?

The usual causes are a different secret or secret format, an `exp` in the past, or an `iss` or `aud` the service does not expect. Check the claims with the claims validator and the signature with the verifier.

Is the secret sent anywhere?

No. Signing uses your browser’s Web Crypto and nothing leaves the page. Still, use a throwaway secret, not one from a live system.

Can I create a token that my Keycloak realm accepts?

Not as the realm’s own token. Keycloak signs with private keys it keeps, and your apps verify with the realm’s public keys. Test tokens made here only work with services you configure to trust your test secret.

Why does the token change completely when I edit one claim?

The payload part changes, and the HMAC over it changes entirely, which is how a signature detects tampering. The header part stays the same.

Should `iat` and `exp` be in seconds or milliseconds?

Seconds since 1970, in UTC. Many libraries reject or misread millisecond values, so divide JavaScript’s `Date.now()` by 1000.

Why is my token different from the one another tool made?

Whitespace or key order in the JSON differs, so the encoded parts differ, and so does the signature. Both tokens are valid; they just encode the JSON differently.

Can I put custom claims in the payload?

Yes. Any JSON object works. Use names that will not clash with registered claims, and keep secrets out, because anyone holding the token can read it.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.