What does openssl rand -base64 32 produce?

32 random bytes, encoded as 44 base64 characters including padding. The number is the byte count before encoding. With -hex 32, the same byte count becomes 64 characters. Both contain 256 random bits.

Output length for 32 random bytes
EncodingCharactersAlphabet
Hex640–9, a–f
Base6444, with paddingA–Z, a–z, 0–9, +, /, =
Base64url43, without paddingA–Z, a–z, 0–9, -, _

Choose the encoding your application expects

Use hex for an application that accepts an arbitrary text secret and benefits from a simple alphabet. Use standard base64 when configuration explicitly calls for it, such as a Laravel APP_KEY. Use base64url for values placed in URLs.

Base64 and base64url represent bytes using different alphabets. A decoder may reject the wrong variant, accept it permissively, or mishandle it. Follow the receiving application's documented format instead of assuming interchangeability.

Generate a secret locally

openssl rand -base64 32
openssl rand -hex 32

The OpenSSL rand manual documents the byte count and encoding flags. Use 32 random bytes for an HS256 key; HS512 requires at least 64. Other algorithms and frameworks can require different lengths.

Alternatives without OpenSSL

Python's secrets module and Node's crypto module provide cryptographic random bytes:

python -c "import secrets; print(secrets.token_hex(32))"
node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"

On PowerShell, use .NET's cryptographic random generator:

$bytes = New-Object byte[] 32
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
[Convert]::ToBase64String($bytes)
$rng.Dispose()

The browser tools above use Web Crypto for local generation. Encoding rules come from RFC 4648. Never put an actual generated secret in documentation, source control or a public example.