Java Keystore 与Openssl Pem 的转换

一般情况,生成证书会用到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


[root@kibana ssl]# keytool -importkeystore -srckeystore cluster.store -destkeystore cluster.store.p12 -srcstoretype JKS -deststoretype PKCS12
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配置


 openssl pkcs12 -in cluster.store.p12  -nodes -nocerts -out server.key
 openssl pkcs12 -in cluster.store.p12  -nodes -nokeys -clcerts -out server.crt



http://www.cnblogs.com/interdrp/p/4880891.html

nginx配置如下:

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值