Generating Base32 string examples

The following are provided as examples of how to generate a Base32 random string. From Wikipedia's article on Base32:

"Base32 uses a 32-character set comprising the twenty-six upper-case letters A–Z, and the digits 2–7."

Please engage your security team before deploying any cryptographic functions into production to ensure they meet the environment’s security requirements.

Please adjust the length of the string generation to fit your security and system requirements.

Windows (PowerShell)

Generate a single 32 character Base32 random string:

C:\> $RNG = [Security.Cryptography.RNGCryptoServiceProvider]::Create()
C:\> [Byte[]]$x=1
C:\> for($r=''; $r.length -lt 32){$RNG.GetBytes($x); if([char]$x[0] -clike '[2-7A-Z]'){$r+=[char]$x[0]}} C:\> $r

Example output (only the final command will produce output):


MacOS and Ubuntu

Run the following command in a terminal to generate a 32 character Base32 random string:

$ LC_ALL=C tr -dc 'A-Z2-7' </dev/urandom | head -c 32; echo

Example output: