Categories
SecOps

How to generate a base64-encoded secret

Use the OpenSSL utility to generate a base64-encoded secret.

Generate random 64-bytes base64-encoded secret.

$ openssl rand -base64 64 | paste --delimiters '' --serial 
FITSy9dGK9BlOOrOqOi3xRaWjMPgR9KQtT0GaPiBaKQ7LcYniHsdsSA78iEy8BmOGAXpkVi7Imp9dZeHfJPptA==

Verify randomly generated secret length.

$ openssl rand -base64 64 | paste --delimiters '' --serial | base64 --decode | wc --bytes
64

Generate random 32-bytes base64-encoded secret.

$ openssl rand -base64 32 | paste --delimiters '' --serial
WNi3oF3NfduzvwUiOPlnDdUUjIlMcv7fX28ms3udpPM=

This solution is beautiful in its simplicity.