Skip to main content
Numbers · 287 tools

JWT Secret Key Generator

Generates cryptographically strong random secret keys for signing JSON Web Tokens

JWT Secret KeysExample — click Generate for yours
  • c450652283162e05e39119775bb50dbdc08dc990f79d3ef19972d288036f865860ce3f84ae79ff8e7609d9af35131f1cdd9f48ee8c812daa54f1d16baaa673ac
    SHA-512
  • 84652c451b7c9fe5745b80f258b79e56e781c4e3febbf3d2e2bd10ecbc9d4f1b773282d09fd5ad0fdfef0333fedde2a48711b495074dc4b024553f649cf93706
    SHA-512
  • 57dca779297e3186a063e7f4f30b7f8767558f13d26caaba0efa798fc44b5e26abb864f937ba8dc8715b05a07653c48c5b489f21057cafcdb24ae7307cb35d4a
    SHA-512

Generated 3 items

See 3 examples
  • Example 1
    c450652283162e05e39119775bb50dbdc08dc990f79d3ef19972d288036f865860ce3f84ae79ff8e7609d9af35131f1cdd9f48ee8c812daa54f1d16baaa673ac
    84652c451b7c9fe5745b80f258b79e56e781c4e3febbf3d2e2bd10ecbc9d4f1b773282d09fd5ad0fdfef0333fedde2a48711b495074dc4b024553f649cf93706
    57dca779297e3186a063e7f4f30b7f8767558f13d26caaba0efa798fc44b5e26abb864f937ba8dc8715b05a07653c48c5b489f21057cafcdb24ae7307cb35d4a
  • Example 2
    6ed4dcd797ac4c20c358ce5573aaab60370ff17ce59f3311a1dfe61842aa4700b76f094a7f95519dd0ccca1f6100cad73ad7a55d1eb30fe36df0c7728fb0a34e
    91db34d5cda6bac233dc9212567d965fe5e44b31e4bb96f4653a31044a55d3a4804fdcc2286379b0e6214eeb7a175aa1714eab1431733b9302cdd5e20498c3c8
    17d2911daf43768705ff3b9ac4720db11ed4a093d8e76ce43e32a9e2a1ad3d9225fd75e4fcd06072df570adbca070bce0277d65aae664fc5f7e211662893ecba
  • Example 3
    9fc3495870db586ad5dafe0b94deb24a8492b34f8db56724f13ff9d55da069318adc0de248b76b84eebdd994a9967b178476e117ec2d2dc5864c66d567c8a35e
    aa6dcbb7c5363a6077ca8a690704ebe90905f1eaac5d44be8564d4fe80ba03350940b552b9de37e19be1f320fc344204e193d73b0e6c126df00deae3769fc679
    d456315fabadac8fc69a37f4984e3238dfacd8fc5f7d7a2a05d6b0ed27eeea36d264c7d6a1f823250b109b8ec98ca5a067148350ff23703819c52c87eab00fbe

About this generator

A JWT secret key generator saves you from one of the most common authentication mistakes: weak or reused signing secrets. HMAC-based JWT algorithms like HS256, HS384, and HS512 are only as secure as the entropy behind their key. This tool produces cryptographically strong keys using secure random generation in your browser — nothing is transmitted or logged. Choose your key length in bytes (64 bytes covers HS512 and everything below it), pick hex, Base64URL, or alphanumeric output, and generate up to a batch at once. Base64URL is compact and library-friendly; hex pastes cleanly into config files; alphanumeric avoids special-character issues in strict YAML parsers or shell environments.

How to use

  1. Set the count field to how many independent keys you need — one per environment is a sensible starting point.
  2. Set the length to 32 bytes for HS256 or 64 bytes for HS512 (64 is the safe default for any algorithm).
  3. Choose a format: Base64URL for most JWT libraries, hex for readability, or alphanumeric for restricted environments.
  4. Click Generate and copy each key directly into your secrets manager, .env file, or CI/CD secret variable.
  5. Never regenerate unless rotating — treat each key as a one-time credential and store it immediately after copying.

Use Cases

  • •Bootstrapping JWT_SECRET in a new Express or Fastify API before first deploy
  • •Rotating a compromised signing key in production and redeploying to invalidate forged tokens
  • •Generating separate 64-byte secrets for access tokens and refresh tokens in a Next.js app
  • •Populating JWT secrets in a Docker Compose secrets block or a Kubernetes Secret manifest
  • •Replacing insecure placeholder secrets left behind by create-app boilerplate templates

Tips

  • →Generate one key per application environment (dev/staging/prod) in a single run by setting count to 3.
  • →Base64URL keys are roughly 25% shorter than hex for the same entropy — useful when environment variable length limits exist.
  • →If your JWT library accepts the raw string, paste Base64URL directly; avoid re-encoding it or you will double-encode and break verification.
  • →For microservice architectures, give each service its own signing secret so a breach in one service cannot forge tokens consumed by another.
  • →After rotating a compromised secret, search your codebase and CI logs for the old key string before considering the incident closed.
  • →Alphanumeric format avoids quoting issues in shell scripts and YAML — use it when you cannot control how the value is interpolated.

FAQ

How long should a JWT secret key be for HS256 vs HS512?

The secret should be at least as long as the hash output: 256 bits (32 bytes) for HS256 and 512 bits (64 bytes) for HS512, which is the widely accepted minimum. Longer is fine. A short secret is the most common way HMAC-signed JWTs get broken, so default to 64 bytes for HS512 and never go below the hash size.

Is it safe to generate JWT secrets in the browser?

Yes — the keys are generated with the Web Crypto API (crypto.getRandomValues), which is cryptographically secure, and run locally so nothing is transmitted. That makes them suitable for real signing secrets at the lengths above. Store the secret in your server environment (never in client code or a repo) and rotate it if it is ever exposed.

What is the difference between hex and base64url for a JWT secret?

Both encode the same random bytes; the difference is representation. Hex uses 0–9 and a–f (two characters per byte). Base64url packs the bytes more compactly using a URL-safe alphabet, so the key is shorter for the same entropy. Pick the format your framework or config expects — many accept either.

Where do I store the generated JWT secret?

In a server-side secret store or environment variable (a .env that is gitignored, or a managed secrets service), never in client-side code, a public repo, or a JWT itself. The secret must stay on the signing/verifying server only. If it leaks, anyone can forge valid tokens, so treat it like a password and rotate on exposure.

Should every environment use a different JWT secret?

Yes — use a distinct secret per environment (development, staging, production) so a leak in one does not compromise the others, and so tokens are not valid across environments. Generate a separate key for each and store each in that environment's secret store. Reusing one secret everywhere widens the blast radius of any exposure.

You might also like

Popular tools from other categories that share themes with this one.