如何分离p12(或pfx)文件中的证书和私钥

p12(或者pfx)文件里一般存放有CA的根证书,用户证书和用户的私钥

假设我们有一个test.p12文件

在安装了openssl的linux服务器上执行以下命令:

提取用户证书:

openssl pkcs12 -in test.p12 -clcerts -nokeys -out cert.pem  //pem格式
openssl pkcs12 -in test.p12 -clcerts -nokeys -out cert.crt  //crt格式

如果需要携带秘钥,则去掉 -nokeys

openssl pkcs12 -in test.p12 -clcerts  -out cert.pem  //pem格式
openssl pkcs12 -in test.p12 -clcerts  -out cert.crt  //crt格式

 

提取私钥:

openssl pkcs12 -in test.p12 -nocerts -out key.pem

 

清除秘钥中的密码(在把秘钥部署到某些服务器上时可能需要清除密码)

openssl rsa -in key.pem -out newkey.pem

 

在java中pkcs12 和jks的相互转换:

JKS → P12
keytool -importkeystore -srckeystore keystore.jks -srcstoretype JKS -deststoretype PKCS12 -destkeystore keystore.p12


 P12 → JKS

keytool -importkeystore -srckeystore keystore.p12 -srcstoretype PKCS12 -deststoretype JKS -destkeystore keystore.jks

 

转载于:https://www.cnblogs.com/jiaoyiping/p/5989046.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值