Random bytes generation with OpenSSL

January 31, 2018
(shell)

Sometimes you just have to generate some random bytes with high entropy. And OpenSSL can help you with this task.

The rand command outputs num pseudo-random bytes. Since in most cases we don’t want to deal with edge bytes, it’s better to use either -hex or -base64 option in order to encode output and thus lead to a valid password.

Another problem is the length. When you use -hex or -base64 option the output string is longer than passed num. In order to keep the desired length, you have to chop it. For example, using the cut command.

Some useful links: