openssl 是什么
openssl是一个密钥管理工具,可以用来生成密钥,进行签名,密钥格式转换。
常用命令
用openssl创建CA证书的RSA密钥(PEM格式):
openssl genrsa -des3 -out ca.key 1024
用openssl创建CA证书(PEM格式,假如有效期为10年):
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -config openssl.cnf
openssl是可以生成DER格式的CA证书的,最好用IE将PEM格式的CA证书转换成DER格式的CA证书。
openssl x509 -req -in client-req.csr -out client-cert.cer -signkey client-key.key -CA root-cert.cer
-CAkey root-key.key -CAcreateserial -days 3650
x509到pfx
pkcs12 -export –in keys/client1.crt -inkey keys/client1.key -out keys/client1.pfx
PEM格式的ca.key转换为Microsoft可以识别的pvk格式。
pvk -in ca.key -out ca.pvk -nocrypt -topvk
PKCS#12 到 PEM 的转换
openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem
验证 openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem
从 PFX 格式文件中提取私钥格式文件 (.key)
openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key
转换 pem 到到 spc
openssl crl2pkcs7 -nocrl -certfile venus.pem -outform DER -out venus.spc
用 -outform -inform 指定 DER 还是 PAM 格式。例如:
openssl x509 -in Cert.pem -inform PEM -out cert.der -outform DER
PEM 到 PKCS#12 的转换,
openssl pkcs12 -export -in Cert.pem -out Cert.p12 -inkey key.pem
openssl pkcs12 -export -in tunnel_am1.crt -out tunnel_am1.p12 -inkey tunnel_am1.key
openssl pkcs12 -export -clcerts -in client-cert.cer -inkey client-key.key -out client.p12
PKCS #8 到 OpenSSL 格式转换.
openssl pkcs8 -nocrypt -inform der < pvt.der > pvt.pem
DER-encoded RSA key 转换为 PEM 格式.
openssl rsa -pubin -inform der < pub.der > pub.pem
To remove the pass phrase on an RSA private key:
openssl rsa -in key.pem -out keyout.pem
To encrypt a private key using triple DES:
openssl rsa -in key.pem -des3 -out keyout.pem
To convert a private key from PEM to DER format:
openssl rsa -in key.pem -outform DER -out keyout.der
To print out the components of a private key to standard output:
openssl rsa -in key.pem -text -noout
To just output the public part of a private key:
openssl rsa -in key.pem -pubout -out pubkey.pem
Output the public part of a private key in RSAPublicKey format:
openssl rsa -in key.pem -RSAPublicKey_out -out pubkey.pem