OpenSSL 命令速查表
OpenSSL 是一个强大的开源加密工具包,广泛用于 SSL/TLS 证书管理、密钥生成、加密解密和 SSL 测试。本速查表汇总了日常运维和开发中最常用的 OpenSSL 命令。
更新: 2026-07-17·33 条命令
概述
OpenSSL 是一个健壮的全功能开源工具包,实现了 SSL 和 TLS 协议。本速查表涵盖密钥生成、证书管理和 SSL 测试。
快速开始
``bash
openssl version # 检查 OpenSSL 版本
openssl help # 列出可用命令
``
详细用法请参阅下方命令表格。
密钥管理(10)
| 命令 | 难度 | ||
|---|---|---|---|
openssl genrsa [numbits]生成 RSA 私钥文件,默认 2048 位 | 基础 | openssl genrsa -out key.pem 4096 | |
openssl ecparam -genkey -name [curve]生成椭圆曲线(EC)私钥,curve 常用 prime256v1 或 secp384r1 | 中级 | openssl ecparam -genkey -name prime256v1 -out ec-key.pem | |
openssl genpkey -algorithm [algo]通用私钥生成工具,支持 RSA、EC、ED25519 等算法 | 中级 | openssl genpkey -algorithm ED25519 -out ed-key.pem | |
openssl pkey [options]处理私钥的通用工具,支持格式转换、查看信息等 | 中级 | openssl pkey -in key.pem -pubout -out pub.pem | |
openssl pkeyutl [options]使用私钥或公钥执行低级签名、验证、加密和解密操作 | 高级 | openssl pkeyutl -sign -in data.bin -inkey key.pem -out sig.bin | |
openssl ec [options]处理 EC 密钥的工具,支持查看、转换格式 | 中级 | openssl ec -in ec-key.pem -text -noout | |
openssl rsa [options]处理 RSA 密钥的工具,支持查看、格式转换、生成公钥 | 中级 | openssl rsa -in key.pem -pubout -out public.pem | |
openssl pkcs8 [options]PKCS#8 格式私钥转换工具,支持加密和未加密的格式 | 中级 | openssl pkcs8 -topk8 -in key.pem -out pk8.pem -nocrypt | |
openssl dsaparam [numbits]生成 DSA 参数文件,用于 DSA 密钥生成 | 中级 | openssl dsaparam -out dsa-params.pem 2048 | |
openssl dhparam [numbits]生成 Diffie-Hellman 参数文件,用于完美前向安全的密钥交换 | 中级 | openssl dhparam -out dhparams.pem 2048 |
CSR(3)
| 命令 | 难度 | ||
|---|---|---|---|
openssl req -new -key [keyfile] -out [csr]基于现有私钥生成新的证书签名请求(CSR) | 基础 | openssl req -new -key key.pem -out request.csr -subj "/CN=example.com/O=MyOrg" | |
openssl req -x509 -newkey [type] -days [n]直接生成自签名证书(含私钥),适合开发和测试环境 | 中级 | openssl req -x509 -newkey rsa:4096 -days 365 -keyout key.pem -out cert.pem | |
openssl req -text -noout -in [csr]查看 CSR 文件的内容详情 | 基础 | openssl req -text -noout -in request.csr |
证书(8)
| 命令 | 难度 | ||
|---|---|---|---|
openssl x509 -in [cert] -text -noout查看 X.509 证书的详细信息,包括颁发者、有效期、SAN 等 | 中级 | openssl x509 -in cert.pem -text -noout | |
openssl x509 -req -in [csr] -CA [ca] -CAkey [key]使用 CA 证书签署 CSR 生成服务器证书 | 中级 | openssl x509 -req -in request.csr -CA ca.pem -CAkey ca.key -out cert.pem -days 365 | |
openssl verify [options] [cert]验证证书链是否有效和可信 | 中级 | openssl verify -CAfile ca-chain.pem server.crt | |
openssl ca [options]模拟 CA 操作的命令,用于签发和管理证书 | 高级 | openssl ca -in request.csr -out signed.pem -config openssl.cnf | |
openssl crl [options]处理证书吊销列表(CRL),支持查看和格式转换 | 高级 | openssl crl -in crl.pem -text -noout | |
openssl ocsp [options]在线证书状态协议(OCSP)客户端,查询证书的实时吊销状态 | 高级 | openssl ocsp -issuer ca.pem -cert server.crt -url http://ocsp.example.com | |
openssl ts [options]时间戳协议(TSP)工具,用于生成或验证数字时间戳 | 高级 | openssl ts -query -data doc.txt -cert -out ts-query.tsq | |
openssl pkcs12 -export [options]将 PEM 证书和私钥打包为 PKCS#12 / PFX 文件 | 中级 | openssl pkcs12 -export -in cert.pem -inkey key.pem -out cert.pfx |
SSL 测试(7)
| 命令 | 难度 | ||
|---|---|---|---|
openssl s_client [options]测试 SSL/TLS 客户端连接,显示证书链和握手详情 | 中级 | openssl s_client -connect example.com:443 -servername example.com | |
openssl s_server [options]启动测试用的 SSL/TLS 服务器,用于调试客户端 | 中级 | openssl s_server -accept 4433 -cert cert.pem -key key.pem | |
openssl speed [algorithm]测试加密算法的性能,支持多种算法的基准测试 | 基础 | openssl speed aes-256-cbc | |
openssl version [options]显示 OpenSSL 版本和编译信息 | 基础 | openssl version -a | |
openssl ciphers [options]查看支持的加密套件列表,支持 SSLv3、TLSv1.2、TLSv1.3 等 | 中级 | openssl ciphers -v 'TLSv1.3' | |
openssl asn1parse [options]解析 ASN.1 结构的文件,用于深度检查证书和密钥的内部编码 | 高级 | openssl asn1parse -in cert.pem -inform PEM | |
openssl prime [options]测试数字是否为素数,或生成素数 | 基础 | openssl prime -generate -bits 128 |
加密解密(5)
| 命令 | 难度 | ||
|---|---|---|---|
openssl enc -cipher [options]对称加密/解密工具,支持 AES、DES、ChaCha20 等算法 | 中级 | openssl enc -aes-256-cbc -salt -in plain.txt -out encrypted.enc | |
openssl dgst [algorithm] [file]计算文件的哈希摘要值,支持 MD5、SHA256、SHA512 等 | 中级 | openssl dgst -sha256 -hex file.txt | |
openssl passwd [options]生成密码哈希值,支持 crypt、MD5、SHA256、SHA512 等格式 | 中级 | openssl passwd -6 -salt xyz123 mypassword | |
openssl rand [nbytes]生成指定字节数的加密安全随机数,可输出到文件或 base64 | 基础 | openssl rand -hex 32 | |
openssl smime [options]S/MIME 邮件加密和签名工具,用于加密/解密和签名/验证邮件 | 高级 | openssl smime -encrypt -aes256 -in email.txt -out encrypted.msg cert.pem |
常见问题
本速查表数据整理自各工具官方文档。最后更新: 2026-07-17。