Choosing a format
- Hex: two characters per byte. The safe default for config files and environment variables, and what
openssl rand -hex 32gives you. - Base64url: shorter for the same randomness and safe in URLs and headers. Common for session secrets and JWT signing keys.
- Base62: letters and digits only, so it survives double-click selection and systems that choke on symbols.
- UUID v4: 122 random bits in the standard 8-4-4-4-12 layout. Fine as an identifier; prefer 32 random bytes for anything secret.
How long should a key be?
128 bits (16 bytes) is enough that guessing is impossible. 256 bits (32 bytes) is the usual choice for signing secrets like AUTH_SECRET or a webhook secret, because some algorithms expect a key that size. Going longer does no harm.
Add a prefix
Prefixes like sk_live_ or ghp_ tell people what a key is and let secret scanners on GitHub and elsewhere catch it if it leaks. If you're issuing keys to your own users, pick a distinctive prefix and register it with your scanner.
Handing the key over
Keys usually end up in a .env file, a CI variable or a client's inbox. Instead of pasting them into email, Send it once puts them in an encrypted link that self-destructs after it's opened. Sending a whole config? Use the .env file sharer. Sending keys from a script or pipeline? The Burn the Secret API creates one-time links programmatically. See also how to send API keys to clients.