p12, jks cer, rfx, pem转换笔记

原文地址:https://www.cnblogs.com/cherrychen-cakuta/p/8028020.html

 

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

//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先堆积在那里下次使用时翻出来玩玩。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值