How to use openssl to generate random bytes
Here's a quick trick to use openssl to generate random bytes.
To generate a random length of bytes use openssl
as follows.
openssl rand <number>
For example to generate 16 random bytes, use the following
openssl rand 16
�j���G$�$�8�l�%
As you can see, some of these bytes are special characters. To generate only hexadecimal characters, use -hex
flag.
openssl rand -hex 16
53ab2643e3a7b3aff571d331dfbc1b9a
To generate base64
characters, use the -base64
flag. This is also very useful for generating random passwords.
openssl rand -base64 16
ZO7QXlw/9WsPyUG+QFcYaQ==