How to generate a secret key
- 1Click a Standard Preset such as AES-256 Key, JWT HS256 Secret, API Key or Django SECRET_KEY. It sets the size and encoding most commonly used for that job.
- 2Or set a Custom Size in bytes (up to 4,096) and pick an Encoding: Hex (lowercase or uppercase), Base64, Base64 URL, Base58 or Alphanumeric.
- 3Check the entropy readout. Anything below 128 bits is flagged, since that's the usual floor for a secret.
- 4Click Copy Secret, regenerate for a new value, or download it as a .txt file. Turn on Bulk Mode to generate up to 100 keys in one go.
What makes a good secret key?
A secret key is only as strong as its randomness. Unlike a password, nobody has to remember it, so it should be pure random bytes with no structure an attacker could exploit. This tool reads those bytes from crypto.getRandomValues, the browser's cryptographically secure random number generator. That's the same class of source as /dev/urandom or Node's crypto.randomBytes. For Base58 and alphanumeric output it uses rejection sampling, so every character is equally likely and there's no modulo bias.
Size is measured in bytes, and each byte is 8 bits of entropy. A 16-byte key gives 128 bits, which is the practical minimum for anything security-sensitive. 32 bytes, or 256 bits, is the standard for AES-256 keys and HMAC-SHA256 secrets, including JWT HS256. Any 32-byte preset, such as AES-256 Key, HMAC-SHA256 or Session Secret, works as a 256-bit key generator; they differ only in encoding. RFC 7518 requires an HS256 key to be at least as long as the hash output, so a short, human-chosen JWT secret is a real weakness, and it's the main reason to use a JWT secret generator rather than typing a phrase. HS512 calls for 64 bytes.
Encoding doesn't change the entropy of byte-based output; it only changes how the bytes are written down. Hex uses two characters per byte and is safe everywhere; if you just need a random hex key generator, the equivalent of openssl rand -hex 32, pick 32 bytes and Hex. Base64 is about a third shorter but contains + and /, while Base64 URL swaps those for - and _ and drops the padding so the key can sit in a URL or filename. Base58 and Alphanumeric draw characters directly from their alphabet, so for those two the size you set is the number of characters, and each one carries about 5.9 bits.
Treat generated keys like any other credential. Put them in environment variables or a secrets manager, never in source control, and generate a different key for each environment so a leaked staging secret can't sign production tokens.
When developers reach for it
JWT and HMAC signing secrets
Use the JWT HS256 Secret or JWT HS512 Secret preset to get a key that meets the minimum length for HMAC-signed tokens. For webhook or request signing, the HMAC-SHA256 preset is an HMAC key generator that gives you 32 bytes in hex.
Encryption keys
Use it as an encryption key generator for AES: the three Encryption presets give you 16, 24 or 32 random bytes in hex, for encrypting data at rest or for a framework's encryption setting.
Framework and app config
The Django SECRET_KEY preset is a Django secret key generator that gives you 50 alphanumeric characters, the same length as Django's own get_random_secret_key() but without the # and $ characters that can trip up .env parsers. The Web / Session presets cover cookie and CSRF secrets too.
API keys and client secrets
The API Key preset makes this an API key generator for URL-safe keys, and the OAuth Client Secret preset covers client secrets. With Bulk Mode it's also a quick random token generator for test fixtures and seed data.
Frequently asked questions
Is it safe to generate secret keys in the browser?
+
Yes. The keys come from crypto.getRandomValues, a cryptographically secure generator, and are created entirely on your device. Nothing is sent to a server and nothing is saved.
How long should a JWT secret be?
+
For HS256, use at least 32 random bytes (256 bits), matching the size of the SHA-256 output. For HS512, use 64 bytes. The presets use exactly those sizes.
What's the difference between Base64 and Base64 URL?
+
Base64 uses + and / and may end in = padding, which need escaping in URLs. Base64 URL replaces them with - and _ and removes the padding, so the key can go in a URL, header or filename as-is.
Does the encoding change how secure the key is?
+
Not for hex and Base64, which just write out the same random bytes in different alphabets. For Base58 and Alphanumeric, the size is a character count, so the entropy is that count times about 5.9 bits.
Can I use this as an AES-256 key generator?
+
Yes. The AES-256 Key preset produces 32 random bytes as 64 hex characters, which most libraries accept directly once decoded from hex.
How do I generate a session secret for Express or Flask?
+
Use the Session Secret preset: 32 random bytes in Base64, which you can paste into express-session's secret option or Flask's SECRET_KEY. Whatever session secret generator you use, it should give you at least 32 bytes from a cryptographically secure source, and each environment should get its own value.
Can I use this as a pre-shared key generator for WPA2 or IPsec?
+
Yes, but use a character-based encoding. A WPA2-Personal passphrase must be 8 to 63 printable characters, so choose Alphanumeric and a size between 32 and 63; 32 characters is about 190 bits. Some routers and wpa_supplicant also accept the raw 256-bit PSK as exactly 64 hex digits, which is 32 bytes in Hex. IPsec devices generally take a plain string, sometimes with a length cap, so Alphanumeric avoids quoting problems in config files.
Related tools
Password Generator
Create strong, secure passwords with customizable length and character sets.
JWT Token Generator
Create signed JWT tokens with custom payloads, choose algorithm (HS256/384/512), and provide your secret key.
SHA-256 Hash Generator
Compute SHA-1, SHA-256, SHA-384, and SHA-512 cryptographic hashes from any text using the Web Crypto API. All processing stays in your browser.
Chmod Calculator
Work out Unix file permissions: tick read/write/execute for owner, group and others, or type an octal mode like 755 or a string like rwxr-xr-x. Get the chmod command in numeric and symbolic form, including setuid, setgid and sticky bits.