Skip to content
Password Generator Lab

API key & secret generator

Random keys, tokens and secrets for apps, APIs, JWT signing and config files.
Your key

Click the key to copy it.

≈ 256 bits · 43 random characters

Format

A–Z, a–z, 0–9, - and _ — compact and safe in URLs, headers and env files.

Strength

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.

UseSuggested
API keys and bearer tokens you issue256-bit Base64URL, with a prefix
JWT HS256 / HMAC-SHA-256 secret256-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 .env files 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:

EnvironmentCommand
Shell (OpenSSL)openssl rand -hex 32
Pythonsecrets.token_urlsafe(32) or secrets.token_hex(32)
Node.jscrypto.randomBytes(32).toString("base64url")
Browser / Deno / Buncrypto.getRandomValues(new Uint8Array(32))
Gocrypto/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?
This page generates keys with your browser's Web Crypto API and never sends them anywhere — you can check the Network tab or use it offline. For production secrets, generating them on the server that uses them (for example with openssl rand) avoids copying a secret through your clipboard at all.
How long should an API key be?
Use at least 128 random bits; 256 bits is the common default. That's 43 characters in Base64URL or 64 in hex.
Can I use this as a JWT secret?
Yes. HS256 needs a key of at least 256 bits, HS384 at least 384 and HS512 at least 512. Choose the matching strength here and keep the key on the server.
Is a UUID a good API key?
Not on its own. A random UUID v4 has 122 random bits, which is hard to guess, but UUIDs are designed as identifiers and RFC 9562 advises against using them as security capabilities. Use a 256-bit random key for secrets.
Does the prefix make the key stronger?
No. The prefix is a readable label that's the same for every key, so it adds no entropy. Its value is operational: you can tell keys apart and secret scanners can recognize them.

Related guides

More generators