Skip to content

JWT secret generator

Free, no sign-up Runs in your browser

Generate a random JWT signing secret of the right size for HS256, HS384 or HS512, as Base64URL or hex, with the rule from RFC 7518. Runs in your browser.

Algorithm
Encoding

Check how your JWT library reads the secret. Many use the string as it is, so the characters themselves become the key; some decode Base64 or hex first.

HS256 signs with HMAC and SHA-256, whose output is 256 bits. RFC 7518 section 3.2 requires a key of at least that size, so this secret is 32 random bytes (256 bits).

HS256 secret
The secret appears here.

Made in your browser with crypto.getRandomValues and not sent anywhere. Put it in an environment variable or a secret manager, not in the code.

Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.

How to use the JWT secret generator

  1. Choose the algorithm your tokens use: HS256, HS384 or HS512.
  2. Choose Base64URL or hex, to match how your library reads the secret.
  3. Press Generate and copy the secret.
  4. Store it as an environment variable or in a secret manager, one per environment.

About this tool

JSON Web Tokens signed with HS256, HS384 or HS512 use HMAC: one secret both signs the token and verifies it. Anyone who knows that secret can mint a token for any user, so the whole scheme rests on the secret being impossible to guess. A token is public by nature, and its signature lets an attacker test guesses offline, as fast as their hardware allows.

That is why the standard sets a floor. RFC 7518 section 3.2 says a key of the same size as the hash output or larger must be used: 256 bits for HS256, 384 for HS384, 512 for HS512. This tool generates exactly that many random bytes. A longer key adds nothing, and a shorter one, or a word or sentence, is the usual way these tokens are broken.

The common mistake is a secret a person typed: the name of the app, a phrase, the placeholder from a tutorial. Cracking tools run through wordlists against a captured token in seconds. Generate the secret, keep it in an environment variable or a secret manager, and use a different one for every environment. If several services need to verify tokens, consider RS256 or ES256, where only the issuer holds the private key.

Sources

Questions

How long should a JWT secret be?

At least as long as the hash output: 32 bytes for HS256, 48 for HS384 and 64 for HS512. RFC 7518 makes that a requirement, and some libraries refuse shorter keys. The bytes must be random; a long sentence does not count.

Should the secret be Base64 or hex?

Either holds the same randomness; what matters is how your library treats the string. Many take the characters as the key bytes directly, in which case the text you copy is the key. Others expect you to decode Base64 or hex first, so check, and do the same thing when signing and verifying.

Can a weak JWT secret be cracked?

Yes, offline. A signed token contains everything needed to test a guess, so an attacker who has one token can try wordlists at high speed without touching your server. With a random 256-bit secret that search cannot succeed.

When should I use RS256 or ES256 instead of HS256?

When the party that verifies tokens should not be able to create them. With HMAC every verifier holds the signing secret. With RSA or ECDSA signatures only the issuer has the private key and verifiers get the public key, which is safer across several services or third parties.

Related tools