About this tool
Hexadecimal is the standard way to write random bytes as text: each hex digit is 4 bits, so two digits make one byte. This generator creates secure random hex strings for keys, salts, nonces, IDs, test vectors and sample data, in any length from one digit to 512.
Every value comes from crypto.getRandomValues(), your browser’s cryptographically secure random number generator, never Math.random(), and nothing is sent to a server.
Common lengths
| Hex digits | Bytes | Bits | Typical use |
|---|---|---|---|
| 16 | 8 | 64 | Trace and span IDs, short random IDs |
| 32 | 16 | 128 | Tokens, salts, AES-128 keys, nonces |
| 40 | 20 | 160 | Same length as a SHA-1 hash or Git commit ID |
| 64 | 32 | 256 | AES-256 and HMAC-SHA256 keys, Flask secret keys |
| 128 | 64 | 512 | Rails secret_key_base, HMAC-SHA512 keys |
Formats
- 0x prefix marks a number as hex in C, JavaScript, Python, Solidity and many other languages.
- Byte separators group the digits in pairs (
3f:a2:09), as used for fingerprints, MAC addresses and hex dumps. - Upper and lower case mean the same value; lowercase is more common in code and hashes.
Random hex in code
# Command line: 32 random bytes as 64 hex digits
openssl rand -hex 32
# Python
import secrets; secrets.token_hex(32)
# Node.js
require('crypto').randomBytes(32).toString('hex')
FAQ
How do I generate a random hex string?
Choose the number of hex digits and click Generate. 32 digits give 128 random bits; 64 digits give 256 bits.
How many bytes is a hex string?
Two hex digits are one byte, so a 64-digit hex string is 32 bytes (256 bits).
Are these hex values secure enough for keys?
Yes. They come from the browser’s cryptographically secure generator. Use at least 32 digits (128 bits) for secrets.
How do I generate random hex on the command line?
Run openssl rand -hex 32 for 32 bytes (64 hex digits), or python -c "import secrets; print(secrets.token_hex(32))".