When working with cryptography, we might need to generate a given number of random bytes. This tutorial shows how to do that using OpenSSL.
The openssl rand
command is used for generating pseudo-random bytes. For example, the following command generates 16 random bytes:
openssl rand 16
The result can be written to a file instead of standard output by using -out
an option.
openssl rand -out test.bin 16
The result can be presented in human-readable form. Use -hex
option to get result as a hexadecimal string.
openssl rand -hex 16
Output example:
718ac48a772f9c35ae39931ba62fecc4
Use -base64
option to get result encoded using Base64.
openssl rand -base64 16
Output example:
GqxYL0J1wDiL+aWyi4iucw==
Leave a Comment
Cancel reply