API key & secret generator
Click the key to copy it.
≈ 256 bits · 43 random characters
A–Z, a–z, 0–9, - and _ — compact and safe in URLs, headers and env files.
A readable label helps you spot and revoke leaked keys (and lets secret scanners find them). It adds no strength. Letters, digits, _, - and . only.
Generated on your device with the Web Crypto API. Never sent anywhere, never stored. How it works
Key facts
- Hex and Base64URL keys encode uniformly random bytes, so a 256-bit key has exactly 256 bits of entropy.
- A 256-bit key is 64 hex characters, or 43 Base64URL or letters-and-digits characters.
- RFC 7518 requires an HS256 JWT signing key of at least 256 bits.
- A random UUID v4 has 122 random bits; RFC 9562 advises against relying on UUIDs being hard to guess.
- A prefix such as myapp_live_ makes keys recognizable but adds no strength.
Last reviewed
How strong should a key be?
Unlike a password, a machine-to-machine secret never has to be remembered or typed, so there's no reason to keep it short. Brute force is already hopeless at 128 random bits — that's 3.4 × 1038 possibilities — but 256 bits is the usual default for signing and encryption secrets, gives a large margin against future advances, and costs nothing but a few more characters.
| Use | Suggested |
|---|---|
| API keys and bearer tokens you issue | 256-bit Base64URL, with a prefix |
| JWT HS256 / HMAC-SHA-256 secret | 256-bit (HS384: 384-bit, HS512: 512-bit) |
Session, CSRF or cookie-signing secret (e.g. framework SECRET_KEY) | 256-bit hex or Base64URL |
| AES-256 key (raw) | 256-bit hex — exactly 32 bytes |
| Database row or request ID (not a secret) | UUID v4 |
Which format?
- Base64URL packs 6 bits into each character using only letters, digits,
-and_, so it's compact and survives URLs, HTTP headers, JSON and.envfiles without escaping. We omit the=padding. - Hex uses 4 bits per character. It's twice as long but universally accepted, and it's what many libraries expect when a key is given as text.
- Letters & digits suits systems that reject any punctuation. Each character is drawn uniformly from 62 with rejection sampling, adding about 5.95 bits; we round the length up so the key always meets the bit strength you picked.
- UUID v4 is a standard identifier format with 122 random bits. Use it to name things, not to protect them.
The format doesn't change how hard a key is to guess — only how many characters carry the same bits. Decode the Base64URL or hex text back to bytes if your library wants raw key material.
Generating keys in code
In production systems, generate secrets where they're used, with your platform's cryptographically secure generator. Each of these produces 256 random bits:
| Environment | Command |
|---|---|
| Shell (OpenSSL) | openssl rand -hex 32 |
| Python | secrets.token_urlsafe(32) or secrets.token_hex(32) |
| Node.js | crypto.randomBytes(32).toString("base64url") |
| Browser / Deno / Bun | crypto.getRandomValues(new Uint8Array(32)) |
| Go | crypto/rand — rand.Read(b) into a 32-byte slice |
Never use non-cryptographic generators such as Math.random(), Python's random module or math/rand for secrets: their output can be predicted.
Handling the key safely
- Keep secrets in environment variables or a secrets manager, never in source code or Git history. A prefix makes accidentally committed keys easy for secret scanners to catch.
- When you issue API keys to others, store only a hash of each key (a fast hash such as SHA-256 is fine for long random keys) and show the full key once, at creation.
- Give each environment and client its own key so you can revoke one without breaking the rest.
- Rotate keys when someone with access leaves or a key may have been exposed.
Need something a person will type? Use the password generator or a passphrase instead, and check the math in the entropy calculator.
Sources
Frequently asked questions
Is it safe to generate an API key on a website?
How long should an API key be?
Can I use this as a JWT secret?
Is a UUID a good API key?
Does the prefix make the key stronger?
Related guides
- How are passwords cracked?How attackers really get passwords: phishing, credential stuffing, online guessing and offline cracking of stolen hashes, and what length and randomness change.
- Are online password generators safe?When an online password generator is safe to use, the red flags that mean it isn't, and three ways to check for yourself in under a minute.
More generators
- Password generatorRandom passwords with full control over length and characters.
- Passphrase generatorMemorable word-based passphrases from the EFF wordlist.
- PIN generatorUniform random numeric PINs, 4–12 digits.
- Wi-Fi password generatorWPA2/WPA3 passphrases that are easy to type on any device.
- Bulk password generatorUp to 100 independent passwords at once.
- Password policy generatorPasswords that meet Entra ID, Active Directory, AWS IAM, PCI DSS and NIST rules.
- Password strength checkerCheck how guessable a password is — entirely on your device.
- Entropy calculatorBits of entropy and time-to-guess for any random password scheme.