ToolboxHub

🎲Random Bytes Generator

Generate cryptographically secure random bytes in hex or base64.

Share:

About Random Bytes Generator

Random Bytes Generator uses the browser's Web Crypto API to produce cryptographically secure random byte sequences, output in hexadecimal or base64 encoding. Use it to generate secure tokens, salts, initialization vectors, API keys, and other security-critical random values.

How to Use Random Bytes Generator

  1. 1

    Set the number of bytes

    Enter the number of random bytes you want to generate (e.g., 16, 32, or 64 bytes).

  2. 2

    Choose the output format

    Select hexadecimal or base64 encoding for the output.

  3. 3

    Generate and copy

    Click 'Generate' to produce new random bytes and copy the result to use as a token, key, salt, or IV in your application.

Common Use Cases

  • Generating secure session tokens or API keys for web applications
  • Creating random salts for password hashing with bcrypt or Argon2
  • Producing initialization vectors (IVs) for AES encryption
  • Generating random nonces for cryptographic protocols

Frequently Asked Questions

Why use cryptographically secure random bytes instead of Math.random()?
Math.random() is a pseudo-random number generator not suitable for security use. The Web Crypto API's getRandomValues() uses the OS's cryptographically secure random source, making it safe for generating tokens, keys, and salts.
How many bytes should I generate for a secure token?
For session tokens and API keys, 32 bytes (256 bits) is the standard recommendation. For initialization vectors (IVs) in AES-GCM, 12 bytes is standard. For salts, 16–32 bytes is typical.
What is the difference between hex and base64 output?
Hex encoding uses characters 0–9 and a–f, producing output twice as long as the byte count. Base64 uses 64 characters and produces output about 1.33× the byte count. Base64 is more compact and common in HTTP headers and JSON payloads.

Related Tools