openssl rand
The OpenSSL command that outputs a chosen number of random bytes from a cryptographically secure generator, used to make keys, IVs and passwords.
In more detail
You give it a number of bytes and optionally an output format: -hex prints each byte as two hexadecimal characters and -base64 prints Base64 text. The bytes come from OpenSSL's cryptographically secure random number generator, so they are suitable for keys, unlike the general-purpose random functions in most programming languages. Keep the output secret and out of shell history and version control, because anyone who sees it holds the key.
Examples
openssl rand -hex 32 > db.key # 32 random bytes, printed as 64 hex charactersopenssl rand -hex 16 > media.ivRelated terms
- CSPRNG — A cryptographically secure pseudorandom number generator: a source of random numbers that attackers cannot predict, used to create keys, nonces and salts.
- OpenSSL — A widely used toolkit and library for cryptography and TLS, including the openssl command-line tool.
- encryption key — A secret value that an encryption algorithm uses to scramble and unscramble data, so that only holders of the right key can read it.
- openssl enc — The openssl subcommand that encrypts or decrypts files and data streams with a symmetric cipher such as AES.
Taught in
- Data States: Security at Rest, in Transit, and in Use — Cybersecurity Fundamentals, GRC & Cryptography
- Asset Lifecycle Management & Media Sanitization — Cybersecurity Fundamentals, GRC & Cryptography