openssl

openssl

Usage

# 生成自签名证书。所有提示输入均可以全部回车跳过
openssl req  -nodes -new -x509  -keyout server.key -out server.cert

# 连接 https 服务器并查看其证书信息。connect 地址的域名只用于获取 IP。
# With SNI
openssl s_client -showcerts -servername example.com -connect example.com:443 | openssl x509 -text
# Without SNI
openssl s_client -showcerts -connect example.com:443 | openssl x509 -text

检测 RSA 公私钥是否匹配

可以使用如下的 openssl 命令检查私钥和公钥中的 modulus(p、q两个大素数的乘积)是否一致。如果两者一致,那么私钥和证书是成对的。modulus长度即为 RSA 密钥长度,例如对于 2048位(Bit) RSA ,modulus 输出为512个字节。

openssl x509 -noout -modulus -in cert.pem
#output: Modulus=C6D43C87B991...

openssl rsa -noout -modulus -in key.pem
#output: Modulus=C6D43C87B991...

Last update: 2023-09-21 01:35:51 UTC