P12,JKS,CER,RFX,PEM轉換速記


1.P12(PKCS12)和JKS互相轉換

1)P12 ——> JKS

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

2)JSK ——>P12

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

2.JKS和CER相互轉換

1)JKS——->CER

keytool -export -alias test -keystore test.jks -storepass 123456 -file test.cer

2)CER——->JKS

keytool -import -v -alias test -file test.cer -keystore test.jks -storepass 123456 -noprompt 

3.PFX(P12)與pEM轉換

使用比較少

1)去除pem格式的key的密碼(輸出的密碼不輸入即可)

openssl rsa -in test.key -out test1.key

2)合並PEM格式輸出PFX(p12)

openssl pkcs12 -export -inkey test1.key -in test.crt -out test.pfx

3)指定intermedian和CA

openssl pkcs12 -export -out test1.pfx -inkey my.private.key -in test.crt -certfile test.crt -CAfile test1.crt 

4)PFX轉回PEM

openssl pkcs12 -in cert2.pfx -out cert22.pem -nodes

5)PEM轉KEY

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

4.DER與PEM轉換

1)DER——->PEM

openssl x509 -in cert.crt -inform der -outform pem -out cert.pem

2)PEM——->DER

openssl x509 -in cert.crt -outform der-out cert.der

5.CER與PEM轉換

1)CER——->PEM

openssl x509 -in cert2.cer -out cert2.pem -outform PEM

2)PEM——–>CERT

這里需要PEM——>PKCS12—–>CRT—–>CER

//PEM-->PKCS12
openssl pkcs12 -export -out cacert.p12 -in cacert.pem //PKCS12-->CRT
openssl pkcs12 -in cacert.p12 -out mycerts.crt -nokeys -clcerts //CRT-->CER
openssl x509 -inform pem -in mycerts.crt -outform der -out mycerts.cer

6.JKS與PEM轉換

這里可能是上面方法的整合,但為了方便以后開發,還是整合好堆積起來比較美。

1)JKS——>PEM

JSK轉換為PEM需要先,JKS–>P12–>PEM

//jks--->p12[需要注意這里必須add -alias keyOwnerAlias 否則會報錯]
keytool -importkeystore -srckeystore sert.jks -destkeystore sert.p12 -srcstoretype jks -deststoretype pkcs12 -alias keyOwnerAlias //p12--->pem
openssl pkcs12 -in sert.p12 -out sert.pem

2)PEM——>JKS

PEM轉換為JKS,需要先PEM—>PFX—->JKS

//PEM--->PFX
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.pem //PFX--->JKS
keytool -importkeystore -srckeystore test.pfx -destkeystore test.jks -srcstoretype PKCS12 -deststoretype JKS

7.JKS文件轉換為KEYSTORE文件

1)JKS—–>KEYSTORE

//JKS--->P12
keytool -importkeystore -srckeystore D:\test.keystore -srcstoretype JKS -deststoretype PKCS12 -destkeystore test1.p12 //P12---->KEYSTORE
keytool -v -importkeystore -srckeystore D:\test.p12 -srcstoretype PKCS12 -destkeystore D:\test.keystore -deststoretype JKS

2)KEYSTORE——>JKS

//keystore--->crt
keytool -export -alias test -file D:\test.crt -keystore D:\test.keystore //CRT-->CER
openssl x509 -inform pem -in test.crt -outform der -out test.cer //CER--->JKS
keytool -import -v -alias test -file test.cer -keystore test.jks -storepass 123456 -noprompt 

 

https://myssl.com/cert_convert.html,該網站也對證書格式轉換提供了支持,但應為很多公司隱私保密政策,還是推薦記住命令or先堆積在那里下次使用時翻出來玩玩。


免責聲明!

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



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