Guide
How to Generate Secure Secret Keys and API Tokens
Learn what makes a good secret key, how to generate one safely, and how to store it without leaking it.
A secret key generator produces cryptographically random bytes and renders them as hex or Base64 strings for use as API keys, tokens, or signing secrets. Strong secrets are the foundation of secure authentication and integrations.
What makes a good secret key
A good secret is long (32 bytes / 256 bits minimum for signing), generated by a cryptographic random source, and never reused across services. Hex doubles the length (64 chars for 32 bytes); Base64 is shorter (44 chars) but may need URL-safe encoding.
Hex vs. Base64
Hex encodes each byte as two characters (0-9a-f), so it is case-insensitive and easy to paste into config. Base64 encodes 3 bytes as 4 characters, so it is more compact but uses +, /, and = which can need URL-safe handling. Pick the format your consuming system expects.
How to generate a secret safely
- Choose a length in bytes (32 is a good default).
- Choose hex or Base64 output.
- Generate using a cryptographic random source (the tool uses the Web Crypto API).
- Copy the secret directly into a secure secret store — never into code.
Examples
A 32-byte hex secret looks like "a3f5...94c2" (64 chars) and works as an HMAC signing key. A 32-byte Base64 secret is about 44 chars and works as a JWT signing key. Both have 256 bits of entropy — infeasible to guess.
Storing secrets safely
- Store secrets in a dedicated secret manager or environment variables, not in source code.
- Never commit secrets to git or log them.
- Rotate secrets if they may have leaked.
- Give each service its own secret; do not share.
Put it into practice
Use the Hash-based Secret Key Generator right now — free, in your browser, no sign-up required.
Try the Hash-based Secret Key GeneratorMore guides
- How to Unscramble Letters Into Words
- How to Find Anagrams of Any Word
- How to Count Words, Characters and Reading Time Accurately
- How to Find Words by Pattern, Length and Letters
- How to Use a Random Word Generator for Games, Writing and Brainstorming
- How to Count Characters (With and Without Spaces)
- How to Convert Text Between Cases (UPPER, lower, Title, camelCase and More)
- How to Clean Up Messy Text (Spaces, Line Breaks and Whitespace)
Related free tools
More free online utilities that pair well with this one — same-category tools for the same task, plus handy extras from other categories.
More generators tools
- Password GeneratorCreate strong, secure random passwords
- Random Number GeneratorGenerate random numbers in any range
- Dummy Data (JSON/CSV) GeneratorGenerate fake JSON & CSV test data
- Lorem Ipsum GeneratorGenerate placeholder Lorem Ipsum text
- UUID v7 / ULID GeneratorGenerate time-ordered UUID v7 & ULID values