About Random Bytes Generator
Get a run of truly unpredictable bytes for a salt, a nonce, an initialisation vector, a session secret or a test fixture. Choose how many bytes you need and the encoding to show first; the same bytes are also given in the other two encodings, each with its own copy button, so you can paste whichever your code or config expects.
The bytes come from your browser’s cryptographic random number generator, the same source Web Crypto uses for keys. They are made on this page and never sent or stored.
How it works
- The bytes are filled by crypto.getRandomValues, the browser’s cryptographically secure generator, in one call per 64 KB.
- Hex writes each byte as two digits. Base64 packs 3 bytes into 4 characters with = padding; Base64URL uses - and _ instead of + and / and drops the padding, so it is safe in URLs and file names.
- Several values at once are generated independently; each line of a download is one value in the encoding you chose.
Questions
Is this the same as openssl rand?
It does the same job. openssl rand -hex 32 and -base64 32 print 32 random bytes in hex or Base64; set the size to 32 here and choose the encoding to get the equivalent.
How many bytes do I need?
For a secret or key, 32 bytes (256 bits) is a strong default. Salts are commonly 16 bytes. A nonce or IV must match what the algorithm requires, for example 12 bytes for AES-GCM.
Why does Base64URL have no = at the end?
The padding is optional in the URL-safe form and is usually left out, because = has a meaning in query strings. Most libraries accept it either way.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.