Use this JWT secret generator to create the jwt signing secrets your API depends on: choose HS256, set the length, and copy a cryptographically secure value without leaving your browser. Your JSON Web Token is only as trustworthy as the secret behind its signature, so a long random key matters more than any clever configuration, and authentication stays safe only while nobody can guess it.
How to Use This JWT Secret Generator
Generating a key takes four quick steps: When a new service needs credentials, the api key generator builds keys from random bytes in the browser, so nothing is sent to a server.
- Pick a length preset: 256, 384 or 512 bits.
- Choose the character set: alphanumeric, special characters, URL safe characters only, or base64 output.
- Set a count for bulk generation when you need separate values for development and staging.
- Press generate, then copy the result to your clipboard.
The page asks the browser's random generator for bytes, so you can generate JWT secrets without trusting a stranger with them.
Why a JSON Web Token Needs a Signing Key
A JSON Web Token is a compact string defined by RFC 7519 that lets a server and a client exchange claims without a stored session. Because the server stays stateless, it relies on one thing to trust an incoming token: the HMAC signature it can recompute with its secret key. Anyone who sees the token can read it, but only the holder of the key can sign or verify it, and a tampered token fails that check.
Every token a service issues carries a header, a payload and a signature, and a token with a missing or altered signature is rejected before any claims are read. That is why authentication depends on the secret rather than on the token's contents, and why security teams treat a random value as a credential, not a setting. When a new service needs a JWT secret key, generate it once, record where it lives, and give the token code only a reference to it.
The Header and Payload Claims
The header names the algorithm, for example {"alg":"HS256","typ":"JWT"}. The payload carries the claims: sub for the user, iss for the issuer, exp for expiry. Both parts are only Base64URL-encoded, never encrypted.
The Signature Your Secret Protects
The signature is the HMAC of the encoded header and payload. Change one character of either and the signature no longer matches, which is why a weak key lets an attacker mint valid tokens.
Choosing a Secret Key Length for HS256, HS384 and HS512
HS256 uses HMAC with SHA-256, so the key should be at least as long as its hash output. A key shorter than that weakens the whole scheme, however well the scheme is built. Longer keys do not hurt, but they add little beyond the strength of the hash itself, so match the length to the option and stop. The table shows the minimum secret length for each option. For database or disk encryption work, the free aes encryption key generator gives developers a standard 256-bit value for symmetric encryption and decryption, with no weak pattern.
| Option | Digest | Minimum secret | Typical use |
|---|---|---|---|
| HS256 | SHA-256 | 32 bytes (256 bits) | General APIs |
| HS384 | SHA-384 | 48 bytes (384 bits) | Compliance-heavy apps |
| HS512 | SHA-512 | 64 bytes (512 bits) | High-security systems |
Character choice changes the math. A 32-character alphanumeric string carries only about 190 bits of high entropy, so it falls short of 256 bits, while 43 alphanumeric characters or 32 random bytes reach the target. A password such as my_password321 falls to a brute force attack in seconds.
Symmetric vs Asymmetric: When RS256 Fits Better
HS256 is a symmetric algorithm: one shared key signs and verifies. If third parties must verify your tokens, an asymmetric pair such as RS256 or ES256 keeps the private key with you and hands out only the public one.
Minimum Secret Length for Each Algorithm
In practice, 32, 48 and 64 bytes cover the three options. Encoded as Base64URL, a 32-byte value becomes 43 characters.
Generating a Random Secret in Node.js, Python and Golang
If you prefer a local secret key generator, your language's cryptographic library does the same job. Whatever the language, create a random secret from a secure source, never a seeded pseudo-random call, and add hashing only where the library asks for it.
Node.js and Python Examples
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
python3 -c "import secrets; print(secrets.token_urlsafe(32))"PHP and OpenSSL Examples
php -r "echo base64_encode(random_bytes(32));"
openssl rand -base64 32The OpenSSL line works on any backend host and gives the same 256-bit result.
Generate JWT Signing Keys for a Staging API: One Worked Case
I'm tightening a staging API before a partner demo, and the first thing I check is its signing value: a 20-character alphanumeric string someone typed months ago. At 62 possible characters each, that is 20 × log₂(62) ≈ 119 bits of entropy, well under the 256 bits that RFC 7518 section 3.2 requires for HS256. So the HS256 tokens it signs are weaker than the algorithm promises.
I choose the 256-bit preset, keep base64 output and generate one value. The 32 random bytes come back as 44 base64 characters, which I copy straight into the staging environment variable. As a cross-check I recompute the size by hand: 44 base64 characters with one padding sign encode 32 bytes, exactly 256 bits.
| Secret | Length | Entropy |
|---|---|---|
| Old typed string | 20 characters | ≈119 bits |
| Alphanumeric, shortened | 32 characters | ≈190 bits |
| Alphanumeric, full | 43 characters | 256 bits |
| Generated random bytes | 32 bytes | 256 bits |
The sensitivity rerun is what I'd watch: switching to alphanumeric only and stopping at 32 characters feels long, yet it lands at about 190 bits, so I keep the byte-based value. The edge case that bit me is encoding. The partner's service decoded the base64 string into bytes while ours used it as plain text, so every signature failed with "invalid signature" even though both held the same string. The fix is to agree on one convention, and I now write it next to the key's name in the secrets manager.
The next action is concrete: restart staging with the new value, confirm a fresh token verifies, and schedule rotation for the day after the demo.
JWT Signing Secrets Best Practices
Follow these best practices once you have a key. Never hardcode it in source code or commit it to git, because a hardcoded value leaks the day someone shares the repository. Choose a strong secret of at least 32 random bytes, keep it stored securely, use a different value for production, and verify every incoming token with an explicit algorithm list so the none algorithm is never accepted. A leaked or guessable value makes your server vulnerable to forged tokens, and OAuth or any other login and authorization flow built on it inherits the weakness. Passwords and secrets are different jobs, so do not reuse a user password as a signing value.
Store the Secret in Environment Variables
Load the value from environment variables or a secrets manager at start-up, for example JWT_SECRET, so the key never appears in your codebase.
Rotate Secrets and Set Short Expiration
Plan key rotation: a written secret rotation policy replaces the value on a schedule and immediately after any incident. Pair it with a short expiration, such as 15 minutes, plus a refresh token, so a stolen token stops working quickly, whatever its payload says.
Is a Browser-Based JWT Generator Safe to Use?
A tool that runs entirely in your browser, with nothing sent over the network, offers real privacy; you can even go offline before you press generate. Check this yourself in the browser's network tab, because a page that submits your value elsewhere is not safe for a production key. For a live system, create the key on a machine you control, then store it only in your secret manager.
Frequently Asked Questions
- Why does the secret length depend on the algorithm?
- HS256, HS384, and HS512 are HMAC constructions over SHA-256, SHA-384, and SHA-512 respectively -- each hash function has a natural digest size (32/48/64 bytes), and using a secret at least that long avoids being the weakest link in the signature's security. A shorter secret doesn't break the algorithm outright, but does reduce the effective security margin below what the hash function itself provides.
- Should I use hex or Base64?
- Either works identically as key material -- most JWT libraries accept a raw string or byte buffer without caring how you originally represented it. Base64 is more compact for storing in environment variables; hex is often easier to paste directly into code during testing. Pick whichever fits your deployment tooling.
- Can I use this secret with RS256 or ES256 instead?
- No -- RS256 and ES256 are asymmetric algorithms that need an actual RSA or ECDSA key pair, not a shared HMAC secret. Use the RSA Key Pair Generator for RS256, or generate an ECDSA pair with your language's standard crypto library for ES256.
- How do I use this secret to actually sign a JWT?
- Pass it as the secret/key argument to your JWT library's signing function (e.g. jwt.sign(payload, secret, { algorithm: 'HS256' }) in Node's jsonwebtoken, or jwt.encode(payload, secret, algorithm='HS256') in PyJWT) -- the same secret must be available wherever tokens are verified, since HMAC is symmetric.
- Where should I store this secret?
- In an environment variable or secrets manager, never hardcoded in source or committed to version control -- anyone with this secret can forge valid, signed tokens for your application, exactly as if they had a master login credential.