What is a secret key?
A secret key is a random value that software uses to sign or encrypt data. Web frameworks use one to sign session cookies, APIs use one to sign JSON Web Tokens, and encryption libraries use one for AES. If it's weak or leaked, attackers can forge sessions or read data.
Developers need fresh, truly random keys when setting up an app, rotating credentials or creating a new environment. This generator produces them at the standard sizes from 128 to 512 bits, using cryptographic randomness, in the encodings frameworks expect.
How to use the Secret Key Generator
1.Choose the key size
256 bits suits most uses, including JWT HS256 and AES-256.
2.Pick the encoding you need
The same key is shown in hex, Base64 and Base64URL.
3.Store it safely
Put it in an environment variable or secrets manager, never in your code.
Example: a 256-bit key
A 256-bit key in each encoding:
- Hex
- 64 characters
- Base64
- 44 characters, ending in =
- Base64URL
- 43 characters, no padding
- Bytes
- 32
All three strings represent the same 32 random bytes.
Same bytes, three spellings
The key is raw random bytes from the Web Crypto API, encoded three ways. Hex uses two characters per byte; Base64 is shorter but includes + and /; Base64URL swaps those for - and _ and drops padding so it's safe in URLs and environment files.
Match the key size to the algorithm: HS256 and AES-256 want 256 bits, HS512 512 bits. Frameworks such as Django's SECRET_KEY, Rails' secret_key_base and NextAuth's secret all expect a long random value like these. Generate a separate key for each environment.
Frequently asked questions
What size key does JWT HS256 need?
At least 256 bits, which is 32 bytes: 64 hex characters.
Is Base64 or hex better?
Neither is stronger. Use whichever format your library or config expects.
Can I reuse a key across apps?
Avoid it. If one app leaks its key, the others are exposed too.
Is this a password?
No. It's a machine secret meant to be stored in config, not typed or remembered.
Related tools
Random String Generator
Random strings from any character set: tokens, codes and test data.
JWT Decoder
Decode a JSON Web Token's header and payload and check its expiry.
Hash Generator: MD5, SHA-1, SHA-256
MD5, SHA-1 and SHA-256 hashes of text or files, with checksum compare.
Base64 Encoder & Decoder
Base64 and Base64url for text (UTF-8) and files.
URL Encoder & Decoder
Percent-encode or decode URLs and query values, and see a URL's parts.
HTML Entity Encoder & Decoder
Escape text to HTML entities, or decode entities back to text.
More Developer tools
JSON & data
CSV tools
Network & system
Web & API
Git & releases
Encoding & security
Text & code
- Regex tester
- Text diff checker
- Cron expression explainer
- Lorem ipsum generator
- Markdown previewer
- Slug generator
- Strip HTML tags
- Unicode character inspector
- URL parser
- Markdown TOC generator
- cURL converter
- Whitespace visualizer
- Markdown link extractor
- Regex escape
- Regex match extractor
- Split text by regex
- HTML, CSS and JS playground
- Mock data generator
- Keyboard event tester
- ASCII table