Skip to content
Devtoolry

Random String Generator

Generate random strings, tokens and API keys online in hex, Base64URL or a custom alphabet, using your browser's cryptographically secure generator.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the Random String Generator

The Random String Generator creates tokens, API keys, salts and IDs from the browser's cryptographically secure random source, in hex, Base64URL or any alphabet you define.

Everything is generated in your browser; nothing you enter is uploaded, and anything random comes from a cryptographically secure source.

How to use the Random String Generator

  1. Choose the length and the alphabet (hex, Base64URL, alphanumeric or custom).
  2. Set how many strings to generate.
  3. Copy the results.

Common mistakes

  • Too short for a secret. Tokens and API keys need at least 128 bits of randomness: 32 hexadecimal or 22 Base64URL characters. Six-digit codes are only suitable when attempts are rate-limited.
  • Characters that break URLs or shells. A custom alphabet with +, /, & or quotes can break URLs, environment files and shell commands. Base64URL and alphanumeric strings are safe everywhere.
  • Using the prefix as part of the secret. A prefix such as sk_live_ labels the key type for people and secret scanners; it adds no randomness. Count only the random part when choosing the length.

Works well with the Random String Generator

Frequently asked questions

How long should an API key be?

At least 128 bits of randomness: 32 hex characters or 22 Base64URL characters.

Is Math.random() used?

No. Values come from crypto.getRandomValues, which is suitable for security purposes.

Should I store API keys in plain text?

Store a SHA-256 hash of the key and compare hashes on each request, like a password. Show the full key to the user only once.

Are the strings unique?

They are random, not checked for duplicates. With 128 bits or more, a collision is so unlikely that it can be ignored.

Guides and tutorials