Linux command
openssl-rand 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate 32 random bytes
openssl rand -hex [32]
Generate 24 random bytes
openssl rand -base64 [24]
Write 256 random bytes
openssl rand -out [path/to/file] [256]
Generate a random password
openssl rand -base64 [16]
说明
openssl rand generates a specified number of pseudo-random bytes using a cryptographically secure pseudo-random number generator (CSPRNG). It calls RAND_bytes(3) internally, which provides 256-bit security strength when properly seeded from the operating system's entropy source. The output can be written as raw binary, Base64-encoded, or hexadecimal. Common uses include generating random passwords, encryption keys, initialization vectors, and nonces for cryptographic operations.
参数
- -help
- Print usage message and exit.
- -out _file_
- Write output to _file_ instead of standard output.
- -base64
- Encode the output using Base64.
- -hex
- Display the output as a hexadecimal string.
- -engine _id_
- Specify an engine for random generation (deprecated in OpenSSL 3.0).
- -rand _files_
- Specify additional random data source files.
- -writerand _file_
- Write random state to _file_ on exit.
- -provider _name_
- Specify the provider to use for random generation.
- -provider-path _path_
- Path to search for providers.
- -propquery _propq_
- Property query for provider selection.
- _num_
- The number of random bytes to generate (required).
FAQ
What is the openssl-rand command used for?
openssl rand generates a specified number of pseudo-random bytes using a cryptographically secure pseudo-random number generator (CSPRNG). It calls RAND_bytes(3) internally, which provides 256-bit security strength when properly seeded from the operating system's entropy source. The output can be written as raw binary, Base64-encoded, or hexadecimal. Common uses include generating random passwords, encryption keys, initialization vectors, and nonces for cryptographic operations.
How do I run a basic openssl-rand example?
Run `openssl rand -hex [32]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -help do in openssl-rand?
Print usage message and exit.