Random Secret Key Generation

To generate a random string of a set size, on linux, run :

# for hex string

openssl rand -hex number

# output:

35d9bbe3576a0866335eea99ba7b6a248f89d07d51c2b30022a8b06f7ac587da

# or for base64 string

openssl rand -base64 number

# output:

8SGmlygNlJFRPtsvcwzI17VYksi2sblO2AD1I2BPLxs=
# hex of length 16
openssl rand -hex 16

# ... 32
openssl rand -hex 32

# ... 64
openssl rand -hex 64

For improved compatibility and reliability, I use the hexadecimal (hex) version of character sets to generate secret keys and database (DB) passwords for my Docker Compose containers.

↑ Back to the top