A secure token is a string of unguessable random data used to authenticate or identify a request — session identifiers, CSRF tokens, API keys, password-reset links, and email-verification codes all rely on them. The single most important property is that the value must come from a cryptographically secure random source. This tool generates tokens using the browser’s Web Crypto API, so every value is suitable for real authentication systems, and nothing ever leaves your device.
How it works
The generator draws random bytes directly from crypto.getRandomValues, the browser’s cryptographically secure pseudo-random number generator (CSPRNG). It then encodes those raw bytes into a text form you can paste into code:
- Allocate a
Uint8Arrayof the byte length you chose. - Fill it with
crypto.getRandomValues(bytes). - Encode the bytes as hex, standard base64, or URL-safe base64url.
Critically, this never uses Math.random, which is predictable and must never be used for anything security-sensitive. A token built from 32 secure random bytes has 256 bits of entropy — far beyond brute-force reach.
Encodings and sizes
- Hex doubles the byte count in characters (32 bytes = 64 hex chars) and is the easiest to read.
- Base64 is compact (about 4 characters per 3 bytes) and standard for headers and cookies.
- Base64url swaps
+/for-_and removes=padding so the token is safe inside URLs and filenames.
For session and anti-CSRF tokens, 32 bytes is a strong, conventional choice. Always store generated secrets in a secure secret manager, never in source control, and rotate them if exposure is suspected.