Numbers
JWT Secret Key Generator
A JWT secret key is the cryptographic foundation of any token-based authentication system. When your application signs a JSON Web Token, the secret key is what makes that signature unique and unforgeable — a weak or reused key is the single most common cause of JWT-based authentication bypasses. This generator produces cryptographically strong random secret keys in hex, Base64URL, or alphanumeric format, suitable for any HMAC-based JWT algorithm including HS256, HS384, and HS512. Key length matters more than it might seem. For HS256, the HMAC-SHA256 algorithm consumes 256 bits, so a 32-byte key is the minimum — anything shorter creates a security gap attackers can exploit through brute force. HS512 works best with 64-byte (512-bit) keys. This generator defaults to 64 bytes, giving you headroom for any HMAC algorithm without needing to regenerate. Format choice depends on your stack. Hex strings are verbose but human-readable and paste cleanly into most config files. Base64URL is compact, URL-safe, and natively understood by most JWT libraries without decoding. Alphanumeric output is useful when your environment restricts special characters in environment variables or secrets managers. Store every generated key in an environment variable or a dedicated secrets manager like AWS Secrets Manager, HashiCorp Vault, or Doppler. Never commit a JWT secret to version control, even in a private repository — leaked secrets in git history remain exploitable long after the commit is deleted.
How to Use
- Set the count field to how many independent keys you need — one per environment is a sensible starting point.
- Set the length to 32 bytes for HS256 or 64 bytes for HS512 (64 is the safe default for any algorithm).
- Choose a format: Base64URL for most JWT libraries, hex for readability, or alphanumeric for restricted environments.
- Click Generate and copy each key directly into your secrets manager, .env file, or CI/CD secret variable.
- Never regenerate unless rotating — treat each key as a one-time credential and store it immediately after copying.
Use Cases
- •Bootstrapping JWT authentication in a new Node.js/Express API
- •Rotating a compromised or expired JWT secret in production
- •Generating per-environment secrets for dev, staging, and prod
- •Configuring HS512 signing in Python FastAPI or Django REST Framework
- •Setting JWT_SECRET in a Docker Compose or Kubernetes secret manifest
- •Providing a strong signing key for Go's golang-jwt/jwt library
- •Creating unique secrets for multi-tenant apps where each tenant gets isolated tokens
- •Replacing default or placeholder secrets left by boilerplate project 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, use at least 32 bytes (256 bits). For HS384, 48 bytes. For HS512, 64 bytes or more. Keys shorter than the algorithm's output size are padded internally, which weakens entropy. Defaulting to 64 bytes covers all three algorithms without ever needing to regenerate when you upgrade.
What format should I use for a JWT secret key — hex or Base64?
Base64URL is more compact and is natively understood by most JWT libraries without extra decoding. Hex is easier to read and paste into config files without worrying about special characters. Alphanumeric is safest for environments where shell variables or YAML parsers choke on characters like +, /, and =.
Can I use these generated secrets in a production environment?
Yes. The keys are generated using cryptographically secure random number generation in your browser. No key is transmitted or logged server-side. Load the key into an environment variable or secrets manager immediately after generating it, and never store it in source code or plain-text config files.
What happens if my JWT secret key is leaked or compromised?
Anyone holding your secret can forge valid tokens for any user, including admins. Rotate the key immediately by generating a new one and redeploying. All existing tokens signed with the old key will become invalid, which forces users to log in again — acceptable collateral damage compared to leaving forged tokens active.
Should I use a different JWT secret for each environment?
Always. Using the same secret across development, staging, and production means a token from a lower-trust environment can authenticate against your production API. Generate a unique secret for each environment and store them separately in your secrets manager or CI/CD pipeline.
How is an HMAC JWT secret different from RSA or ECDSA keys?
HMAC algorithms (HS256, HS384, HS512) use a single shared secret for both signing and verification — any service with the secret can issue tokens. RSA and ECDSA use a private key to sign and a public key to verify, letting you share verification capability without granting signing rights. Use asymmetric keys when multiple services need to verify but only one should sign.
How do I set a JWT secret as an environment variable in Node.js?
Add JWT_SECRET=your_generated_key to a .env file (never committed to git), then load it with dotenv: require('dotenv').config(). Access it as process.env.JWT_SECRET and pass it directly to your sign and verify calls. In production, inject the variable through your hosting platform or secrets manager rather than a .env file.
Can I use the same JWT secret for access tokens and refresh tokens?
You can, but it's better practice to use separate secrets. If your access token secret leaks, an attacker can also forge long-lived refresh tokens, extending the damage window significantly. Generate two distinct keys — one for each token type — so a compromise of one doesn't cascade into the other.