Skip to content

API key generator

Free, no sign-up Runs in your browser

Generate random API keys as hex, Base64URL or Base62, from 16 to 64 bytes, with an optional prefix such as sk_live_. Entropy shown. Runs in your browser.

Format

Base62 is letters and digits only, so a double-click selects the whole key. Base64URL adds - and _. Hex is the longest.

A prefix says what a key is and lets secret scanners find it when it leaks. It is not secret and adds no entropy.

API key
The key appears here.

On your server, store only a hash of the key (SHA-256 is enough for a key this random) and compare hashes when a request comes in. Show the key to its owner once. Then a leaked database does not leak working keys.

Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.

How to use the API key generator

  1. Choose a format: Base62, Base64URL or hex.
  2. Set the number of random bytes. Thirty-two is a good default.
  3. Add a prefix if you want keys that say what they are, then press Generate.
  4. Copy the key. On your server, store only its hash.

About this tool

An API key is a password for a program, so it should be long, random and never chosen by a person. This tool draws the bytes from your browser’s cryptographic random source and writes them in the format you pick. Thirty-two bytes, 256 bits, is a sound default, and 16 bytes, 128 bits, is the least worth issuing. A key that random cannot be guessed, so its risks are all about where it ends up.

The three formats carry the same randomness in different alphabets. Hex is the longest and the safest to paste anywhere. Base64URL is shorter and safe in URLs and headers. Base62 uses letters and digits only, so a double-click selects the whole key. A prefix such as sk_live_ adds no security by itself, but it tells people and secret scanners what the string is, which is how leaked keys get found and revoked quickly.

The common mistake is on the server side: storing keys as they are. Store a hash of each key instead, and compare hashes when a request arrives. Because the key is random and long, a plain SHA-256 is enough; the slow hashes used for passwords are not needed. Show the full key to its owner once, at creation, and keep only the hash and perhaps the last four characters.

Sources

Questions

How long should an API key be?

At least 128 bits of randomness, which is 16 bytes: 32 hex characters or 22 of Base64URL. Many providers use 256 bits. Beyond that there is no security gain, only longer strings.

Should API keys be hashed in the database?

Yes. If the table leaks, hashed keys cannot be used, while stored keys work at once. A single SHA-256 is appropriate here because a 128-bit random key cannot be found by guessing, unlike a human password, which needs a slow hash such as Argon2id or bcrypt.

Why do API keys have prefixes like sk_live_?

A fixed prefix identifies the issuer and the kind of key. It lets support staff tell a live key from a test key, and lets secret scanners match leaked keys with few false alarms. GitHub changed its token format in 2021 for that reason.

Is a UUID a good API key?

A version 4 UUID has 122 random bits, which is enough in size, but UUIDs are designed as identifiers, and other versions carry timestamps and little randomness. RFC 9562 advises against relying on UUIDs as security capabilities. A purpose-made random key avoids the question.

Related tools