Skip to main content

Free Secret Key & API Key Generator – Cryptographically Secure

Generate cryptographically secure random secret keys for JWT, API keys, session secrets, and encryption keys in hex, base64, base64url, or alphanumeric. Runs entirely in your browser.

Written & reviewed by Helperzy Editorial Team · Updated July 2026

WebCryptoRejection Sampling256-bitNo UploadFree

Quick Presets

Custom Configuration

Key Properties

256

bits of entropy

64 chars

output string length

hex

encoding format

Why Not Math.random()?

Math.random() uses a PRNG (xorshift128+ in V8) whose internal state can be reconstructed from observed outputs. A key generated with it is predictable to an attacker who has seen other random values from the same page load. crypto.getRandomValues() pulls from the OS entropy pool (CryptGenRandom on Windows, /dev/urandom on Linux, SecRandomCopyBytes on macOS) and is cryptographically secure.

How to Store Secrets

  • Store in .env.local (gitignored), never committed to the repository.
  • Use a secret manager in production (AWS Secrets Manager, Vault, Doppler).
  • Rotate immediately after any suspected exposure or team member departure.
  • Keep separate secrets per environment (dev, staging, production).

Related Tools

For a secret meant to be typed or remembered, try the Passphrase Generator. For hashing passwords before storage, see the Bcrypt Hash Generator.

100% Private

Keys are generated entirely in your browser via the Web Crypto API. No key is ever transmitted, logged, or stored anywhere — closing this tab erases everything.

How to Use Secret Key & API Key Generator

1

Pick a Preset or Key Size

Choose a preset like JWT Signing Secret, NEXTAUTH_SECRET, or Encryption Key to get the right size and format automatically, or select a custom bit length such as 128, 256, or 512 bits when you know exactly what your service requires.

2

Choose the Output Encoding

Select hex, base64, base64url, or alphanumeric depending on what your library expects. Hex suits encryption keys, base64 suits JWT secrets, base64url suits tokens, and alphanumeric avoids special characters for maximum compatibility across systems.

3

Generate and Copy the Key

Click generate to produce one or more cryptographically secure keys using the Web Crypto API. Copy any key with one click, or use the .env-ready line to paste a named environment variable straight into your configuration file.

How Secret Key Generation Works and Why Math.random Is Unsafe

A secret key generator produces cryptographically random strings suitable for API keys, JWT signing secrets, session secrets, encryption keys, and other credentials that software systems need but humans never have to memorize or type. Unlike a password, nobody needs to recall a secret key from memory, so the only requirements are unpredictability and sufficient length. Developers configuring a new backend service, setting environment variables like NEXTAUTH_SECRET for a web app, or rotating a webhook signing secret after a security incident are the typical audience for a tool like this, because generating a genuinely random key correctly is harder than it looks. The generator fills a byte array of the chosen length using crypto.getRandomValues, the same cryptographically secure random number source browsers use for generating TLS session keys, then encodes those raw bytes into the requested output format: hex (two characters per byte), standard base64, URL-safe base64url with plus and slash replaced and padding removed, or a custom alphanumeric alphabet. The alphanumeric encoding uses rejection sampling rather than a plain modulo on each random byte, since modulo would bias the output toward earlier characters in the alphabet whenever the byte range is not an exact multiple of the alphabet's length. A 256-bit key, the most common size here, is exactly 32 random bytes, which becomes 64 hexadecimal characters, roughly 44 base64 characters including padding, or 43 base64url characters without it. Generating a 256-bit key for use as a NEXTAUTH_SECRET, one of the built-in presets, produces 32 random bytes and encodes them as base64, yielding a 44-character string ending in a single padding character that you paste directly into a .env file. Choosing the encryption-key preset instead outputs the same 256 bits of entropy as 64 hexadecimal characters, since hex is the conventional format most crypto libraries expect when configuring AES-256, which needs exactly 32 bytes of key material. A UUIDv4, generated separately via crypto.randomUUID, looks structurally different and packs only 122 truly random bits because four bits are fixed to mark the version and two more mark the variant, so it should not be treated as equivalent to a full 128-bit random key. Backend developers setting up a new Express or Next.js project need a JWT signing secret or NEXTAUTH_SECRET before their authentication flow will even start, and generating one here in base64 or hex format, then pasting the .env-ready output line directly into a config file, skips the error-prone step of typing a random-looking string by hand, which is often not random at all. Teams rotating a webhook signing secret after a partner integration is decommissioned, or after a suspected leak, generate a fresh hex-encoded key and update both sides of the integration simultaneously, since a webhook signature check fails safe by rejecting the payload if the secrets do not match. Anyone configuring self-hosted software that asks for a session secret or encryption key in its setup wizard can generate several candidates at once and pick the size the documentation specifies. Never use Math.random to generate a secret: it is a fast, statistically-fine random number generator for animations and games, but it is not cryptographically secure, meaning its internal state can sometimes be reconstructed from observed outputs, which is disastrous for a value meant to be unguessable. Store generated secrets in environment variables or a dedicated secret manager, never committed into a Git repository, not even a private one, since repository history is permanent and secrets committed once are considered compromised even after deletion; rotate them periodically and immediately after any suspected exposure. Everything on this page runs through the Web Crypto API locally in your browser, with no key ever transmitted or stored anywhere, so each key you generate is yours alone the moment it appears.

Secret Key & API Key Generator Formula & Method

bytes = crypto.getRandomValues(new Uint8Array(bits / 8)). Encodings: hex = 2 chars/byte; base64 ~= ceil(bytes/3)*4 chars (with padding); base64url = base64 without padding, +/ replaced by -_. Alphanumeric via rejection sampling to avoid modulo bias. 256-bit key = 32 bytes = 64 hex chars = 44 base64 chars = 43 base64url chars. UUIDv4 = 122 random bits (6 bits fixed for version/variant).

Examples: Secret Key & API Key Generator

Input

256-bit key, hex encoding

Result

64 hexadecimal characters (32 random bytes)

256 bits / 8 = 32 bytes, and hex uses 2 characters per byte, so the key is exactly 64 hex characters — the format most libraries expect for AES-256.

Input

256-bit key, base64 encoding (NEXTAUTH_SECRET preset)

Result

A 44-character base64 string ending in one '=' padding character

32 bytes base64-encoded is ceil(32/3)*4 = 44 characters including padding, ready to paste as NEXTAUTH_SECRET in a .env file.

Input

UUIDv4 via crypto.randomUUID

Result

36-character UUID with 122 bits of randomness

Four bits are fixed for the version and two for the variant, so a UUIDv4 carries 122 random bits — a unique identifier, not a full 128-bit secret.

Frequently Asked Questions – Secret Key & API Key Generator

For JWT signing (HS256), session secrets, and most API keys, 256 bits (32 bytes) is the standard and is what the presets default to. AES-256 encryption needs exactly 32 bytes. Larger keys like 384 or 512 bits are available but rarely necessary for these uses.