Secret Key Generator
About this tool
About Secret Key Generator
Application frameworks and protocols need random secret keys: a JWT HS256 signing secret, a Django or Rails SECRET_KEY, a session or cookie secret, an HMAC key for webhooks, or a raw AES-256 key. This generator creates them from your browser's cryptographically secure random generator. Choose the size (128, 192, 256, 384, 512 or 1024 bits) and the encoding: hex for OpenSSL and most config files, standard Base64 with padding, or URL-safe Base64url without padding for JWK files, URLs and headers. The panel shows exactly how many bytes and characters you get. Switch the output to .env line and name the variable to get lines you can paste straight into an environment file, and generate up to 50 keys at once. The keys are created on your device, are never transmitted or logged, and disappear when you close the tab, so treat what you copy as the only copy and store it in a secrets manager.
Built and maintained by Abhi JainUpdated
How to Generate a Secret Key
- 1
Choose the key size
Pick a Key size. 256-bit suits JWT HS256, HMAC-SHA256, session secrets and AES-256.
- 2
Choose the encoding
Select Hex, Base64 or Base64url, and switch Output to .env line if you want NAME=value lines.
- 3
Copy the key
Copy the key into your secrets manager or environment, or click Regenerate for new ones.
Secret Key Generator: questions and answers
How long should a JWT secret be?
For HS256 use at least 256 bits (32 random bytes), which RFC 7518 requires as the minimum key size for HMAC-SHA256. Use 384 bits for HS384 and 512 bits for HS512.
Hex or Base64: which should I use?
Both hold the same random bytes. Hex is 2 characters per byte and is what OpenSSL and many configs expect. Base64 is shorter (4 characters per 3 bytes). Use Base64url when the key goes into a URL, header or JWK, because it has no + / or = characters.
Is this random enough for cryptography?
Yes. The bytes come from crypto.getRandomValues, the browser's cryptographically secure random generator, which is seeded by the operating system.
Can I use this as an AES key?
Yes. A 256-bit key in hex is exactly what AES-256 needs, for example with openssl enc -K. Never reuse an IV or nonce with the same key; generate those separately for each message.
Are the keys stored or sent anywhere?
No. They are generated on your device and never leave it. Nobody, including us, can recover a key you didn't save.
Ready-made Secret Key Generator presets
Related Tools
- Random String GeneratorRandom strings from preset or custom alphabets: letters, hex, Base58, URL-safe and more.
- Key Pair GeneratorEd25519, ECDSA and RSA key pairs in OpenSSH, PEM and JWK formats, generated in your browser.
- Password GeneratorStrong random passwords with a live strength and entropy estimate.
- Encrypt TextTurn a message into password-protected AES-256 ciphertext you can paste anywhere.