Hex Generator

Generate cryptographically secure random hexadecimal strings for encryption keys, salts, and tokens.

—

What is a hex generator?

A hex generator produces random bytes and displays them as hexadecimal text — base-16 digits 0-9 and a-f, each pair representing one byte. Hex is the standard human-readable form for cryptographic material like AES keys, HMAC secrets, salts, and hash digests such as SHA-256 output.

How it works

The generator fills a byte buffer with crypto.getRandomValues(), then converts each byte to a two-character hex pair via toString(16).padStart(2, '0'). Adjust the length slider to choose the output size — 64 hex characters (32 bytes / 256 bits) is a common default for symmetric keys.

Worked example

To create an AES-256-GCM key, generate a 64-character hex string here, then in your server code decode it with Buffer.from(hex, "hex") to get the raw 32-byte key ready to pass into your crypto library.

Common mistakes

  • Using an odd-length hex string, which doesn't map cleanly to whole bytes.
  • Treating the hex string itself as the key length in bits (it's actually 4 bits per hex character).
  • Generating keys with a non-cryptographic RNG for production encryption.
  • Hardcoding a generated key into source control instead of a secrets manager or environment variable.

Security notes

All randomness is produced locally using the Web Crypto API — no values are sent over the network. Rotate cryptographic keys periodically and never reuse the same key across unrelated systems.

Code examples

JavaScript
const bytes = new Uint8Array(32);
crypto.getRandomValues(bytes);
const hex = Array.from(bytes, b => b.toString(16).padStart(2, "0")).join("");
Node.js
import { randomBytes } from "crypto";
const key = randomBytes(32).toString("hex");

Hex Generator FAQ

What is hexadecimal used for in development?

Hex is a compact way to represent binary data as text using 16 symbols (0-9, a-f). It's used for cryptographic keys, color codes, memory addresses, hashes (e.g. SHA-256 output), and byte-level debugging.

How many bytes does a hex string represent?

Each byte is represented by exactly 2 hex characters, so a 64-character hex string encodes 32 bytes (256 bits) — a common key length for AES-256 or HMAC secrets.

Is this generator cryptographically secure?

Yes — bytes come from crypto.getRandomValues(), suitable for generating encryption keys, salts, and secrets.

Can I use a hex string as an AES key?

Yes, many crypto libraries accept a hex-encoded key which you then decode to raw bytes before use — a 64-character hex string decodes to the 32 bytes needed for AES-256.

What's the difference between hex and Base64 for keys?

Hex is twice as long as the underlying bytes but universally readable and easy to copy without escaping issues; Base64 is more compact (~33% overhead) but includes characters that sometimes need URL-encoding.

Can I generate an odd-length hex string?

This tool always outputs an even number of characters since hex represents whole bytes; trimming to an odd length isn't meaningful for byte data.

Related tools