如何分離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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM