Skip to the content.

OpenSSL RSA 加密/解密 签名/验签 自签名证书

2020-07-04 10:00:00


Commands

生成私钥

openssl genrsa -out key.pem

导出公钥

openssl rsa -in key.pem -pubout -out pubkey.pem

加密

openssl rsautl -encrypt -inkey pubkey.pem -pubin -in plain.txt -out cipher.txt

解密

openssl rsautl -decrypt -inkey key.pem -in cipher.txt -out plain.txt

签名

openssl rsautl -sign -in file -inkey key.pem -out sig

验签

openssl rsautl -verify -in sig -inkey key.pem

自签名证书

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out req.pem
// 下面这个版本不加密且解决Safari正常但Chrome访问NET::ERR_CERT_COMMON_NAME_INVALID
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -addext "subjectAltName = DNS:localhost" -out req.pem

注: