How to use
- Set the length and choose whether it counts bytes of random data or Base64 characters. For a key, use bytes: 32 bytes is a 256-bit key.
- Set how many strings you need and the separator between them: new line, comma or space.
- Choose the Standard or URL-safe variant. With the bytes unit you can also turn padding off if the target system does not expect = signs.
- Click Generate for fresh values, then Copy all or Download the list.
Bytes, characters and entropy
The strength of a random string is measured in bits of entropy. Every random byte adds 8 bits, so 16 bytes give 128 bits and 32 bytes give 256 bits. Base64 only changes how those bytes are written: each character carries 6 bits, and every 3 bytes become 4 characters. The tool shows the entropy of each string, so you can check it at a glance.
With the bytes unit, the output decodes to exactly that many random bytes, which is what keys and secrets need. With the characters unit, you get an exact number of characters, each picked uniformly from the 64-character alphabet; use it when a system asks for a token of a fixed length and stores it as text.
| Bytes | Base64 characters | Entropy | Typical use |
|---|---|---|---|
| 12 | 16 | 96 bits | AES-GCM nonce (IV) |
| 16 | 24 (22 without padding) | 128 bits | Salts, session and CSRF tokens, AES-128 keys |
| 32 | 44 (43 without padding) | 256 bits | AES-256 and HMAC-SHA256 keys, HS256 secrets, API keys |
| 64 | 88 (86 without padding) | 512 bits | HMAC-SHA512 keys, HS512 secrets |
Where random Base64 values are used
- JWT secrets. RFC 7518 requires an HMAC key at least as long as the hash output: 32 bytes for HS256, 48 for HS384 and 64 for HS512. Some libraries use the secret string as is, others Base64-decode it first, so check which one yours expects. The JWT decoder verifies HS256 to HS512 signatures with either kind of secret, and the HMAC generator accepts a key as text, hex or Base64.
- Application keys. Laravel, for example, keeps a 32-byte encryption key in its
.envfile asAPP_KEY=base64:..., the same form as a 32-byte string from this tool. - Kubernetes Secrets. Values under
datamust be standard Base64 with padding. A string generated in bytes mode with the Standard variant and padding on can go there directly, and the Pod receives the raw random bytes. If the application expects the Base64 text itself, put it understringDatainstead. - Tokens in URLs. Password reset links, invitation codes and other tokens that travel in URLs should use the URL-safe variant, which replaces
+and/with-and_. See Base64URL for details.
Why crypto.getRandomValues and not Math.random
Math.random() is a fast general-purpose generator. Its output is not designed to be unpredictable, and with some engines the internal state can be reconstructed from a handful of values. This tool uses crypto.getRandomValues(), a cryptographically secure generator seeded by the operating system, the same kind of source behind openssl rand and Python's secrets module. The values are created on your device and are never sent or stored.
Generate random Base64 in code
# Shell: 32 random bytes as Base64 (44 characters)
openssl rand -base64 32
head -c 32 /dev/urandom | base64
# Python
import base64, secrets
base64.b64encode(secrets.token_bytes(32)).decode()
secrets.token_urlsafe(32) # URL-safe, no padding, 43 characters
// Node.js
const crypto = require('crypto');
crypto.randomBytes(32).toString('base64');
crypto.randomBytes(32).toString('base64url'); // URL-safe, no padding
// Browser
const bytes = crypto.getRandomValues(new Uint8Array(32));
btoa(String.fromCharCode(...bytes));
Frequently asked questions
How long should a random key or secret be?
16 bytes (128 bits) is enough for values that only need to be unique and impossible to guess, such as session IDs, CSRF tokens and salts. Use 32 bytes (256 bits) for AES-256 keys, HMAC-SHA256 keys and HS256 secrets, and 64 bytes for HMAC-SHA512 and HS512.
Is this the same as openssl rand -base64 32?
= and decodes to 32 random bytes. The values themselves are of course different every time.Should I use the bytes or the characters unit?
Use bytes when the string will be decoded, as with encryption keys and Kubernetes Secrets. Use characters when a system needs a token of an exact length and uses the text as is. A string from the characters unit is only guaranteed to decode cleanly when its length is a multiple of 4.
When do I need the URL-safe variant?
/ splits URL paths and + turns into a space in form-encoded query strings. URL-safe Base64 uses - and _ instead and is usually written without padding.Are the generated values stored or sent anywhere?
No. They are generated by JavaScript in your browser, never transmitted and gone when you leave the page. Once you use one as a real secret, keep it in a password manager or secret store rather than in chat messages or tickets.