ssl证书格式互换

发布 : 2020-07-31 浏览 :

ssl证书格式互换

从Let’s Encrypt获取的证书是pem格式
如果服务器是nginx还好,但如果是apache,tomcat和iis就需要转换了

1.P12(PKCS12)和JKS互相转换

(1)P12 ——> JKS

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

(2)JSK ——>P12

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

2.JKS和CER相互转换

(1)JKS——->CER

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

(2)CER——->JKS

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

3.PFX(P12)与pEM转换

使用比较少

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

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

(2)合并PEM格式输出PFX(p12)

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

(3)指定intermedian和CA

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

(4)PFX转回PEM

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

(5)PEM转KEY

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

4.DER与PEM转换

(1)DER——->PEM

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

(2)PEM——->DER

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

5.CER与PEM转换

(1)CER——->PEM

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

(2)PEM——–>CERT

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

1
2
3
4
5
6
//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

1
2
3
4
//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

1
2
3
4
//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

1
2
3
4
//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

1
2
3
4
5
6
//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://www.cnblogs.com/cherrychen-cakuta/p/8028020.html

本文作者 : zhouinfo
原文链接 : http://blog.zhouinfo.site/2020/07/31/ssl%E8%AF%81%E4%B9%A6%E6%A0%BC%E5%BC%8F%E4%BA%92%E6%8D%A2/
版权声明 : 本博客所有文章除特别声明外,均采用 CC Apache License 2.0 许可协议。转载请注明出处!
留下足迹