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轉換

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

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積累起來用到時找出來耍一耍。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容