OpenSSL Secure Generation
Generate cryptographically secure random data using openssl rand.
Password/Secret Generation
CODEBLOCK0
Common Lengths
| Use Case | Command |
|---|
| Password (strong) | INLINECODE1 |
| API key |
openssl rand -hex 32 |
| Session token |
openssl rand -base64 48 |
| Short PIN (8 digits) |
openssl rand -hex 4 | xxd -r -p | od -An -tu4 | tr -d ' ' | head -c 8 |
Notes
- -
-base64 outputs ~1.33x the byte count in characters - INLINECODE6 outputs 2x the byte count in characters
- Pipe through
tr -dc to filter character sets - Always use at least 16 bytes (128 bits) for secrets
OpenSSL 安全生成
使用 openssl rand 生成加密安全的随机数据。
密码/密钥生成
bash
32 字节随机数据,base64 编码(43 个字符,通过 tr 实现 URL 安全)
openssl rand -base64 32 | tr +/ -_ | tr -d =
24 字节随机数据,十六进制编码(48 个字符)
openssl rand -hex 24
字母数字密码(32 个字符)
openssl rand -base64 48 | tr -dc a-zA-Z0-9 | head -c 32
常用长度
| 用途 | 命令 |
|---|
| 密码(强) | openssl rand -base64 24 |
| API 密钥 |
openssl rand -hex 32 |
| 会话令牌 | openssl rand -base64 48 |
| 短 PIN 码(8 位数字) | openssl rand -hex 4 | xxd -r -p | od -An -tu4 | tr -d | head -c 8 |
注意事项
- - -base64 输出的字符数约为字节数的 1.33 倍
- -hex 输出的字符数为字节数的 2 倍
- 通过管道使用 tr -dc 过滤字符集
- 密钥始终使用至少 16 字节(128 位)