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 64 character Base32 random string:

C:\> $RNG = [Security.Cryptography.RNGCryptoServiceProvider]::Create()
C:\> [Byte[]]$x=1
C:\> for($r=''; $r.length -lt 64){$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):

JZ3I66NGNBHFA3PZRIUA46XNYXQJM6SFIWSXO6T3GUNFEDQFHPQRMHVSS3MAZCUC

MacOS and Ubuntu

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

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

Example output:

ERN7C3DG3GWBKDF6JXRCQIAF4M24GMQ7NZXL5JF4XPQU45N3R642VTCKHTIRU72W

Comments

0 comments

Please sign in to leave a comment.