ZapKit

Secret Key Generator

Generate random secret keys for JWT signing, HMAC, AES encryption, session cookies and app settings, shown as hex, Base64 and Base64URL.

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. 1.Choose the key size

    256 bits suits most uses, including JWT HS256 and AES-256.

  2. 2.Pick the encoding you need

    The same key is shown in hex, Base64 and Base64URL.

  3. 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.

More Developer tools