Openssl
2026-03-31
新闻来源:网淘吧
围观:13
电脑广告
手机广告
OpenSSL 安全生成
使用以下命令生成密码学安全的随机数据openssl rand。
密码/密钥生成
# 32 random bytes as base64 (43 chars, URL-safe with tr)
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='
# 24 random bytes as hex (48 chars)
openssl rand -hex 24
# alphanumeric password (32 chars)
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 |
注意事项
-base64输出的字符数约为字节数的 1.33 倍-hex输出的字符数为字节数的 2 倍- 通过管道传递至
tr -dc以过滤字符集 - 始终至少使用16字节(128位)作为密钥长度

文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~