一般情况,生成证书会用到java的keytool生成自签名证书,用在tomcat、applet等场合,生成的证书都是二进制文件,不能直接在nginx、或需要pem的场合下使用,因此需要对其进行各种常用转换,下面是一个典型的使用场景。
1 利用keytool生成store并转换为PKCS#12
keytool -genkey -alias clusterkey -dname "CN=xxxx" -keyalg RSA -keystore cluster.store -storepass 123456 -keypass 123456
Enter destination keystore password:
Re-enter new password:
Enter source keystore password:
Entry for alias clusterkey successfully imported.
2 生成certificate.pem和privatekey.pem
[root@kibana ssl]# openssl pkcs12 -nocerts -nodes -in cluster.store.p12 -out cluster-private-key.pem
Enter Import Password:
MAC verified OK
只复制“BEGIN CERTIFICATE” “END CERTIFICATE” 到新文件 cert.pem
[
pem里面内容(下的一样):
-----BEGIN CERTIFICATE-----
。。。。
-----END CERTIFICATE-----
]
只复制 “BEGIN RSA PRIVATE KEY” “END RSA PRIVATE KEY” 到新文件private.pem
3keytool导出certificate后则可以使用:
keytool -export -alias clusterkey -file cluster-pub.cer -keystore cluster.store -storepass 123456
openssl x509 -in cluster-pub.cer -inform DER -out cluster-pub.pem -outform PEM
3 Ngix配置
http://www.cnblogs.com/interdrp/p/4880891.html
nginx配置如下: