How to convert trust certificate from .jks to .pem?

。_饼干妹妹 提交于 2019-12-05 03:19:11
Chris Molanus

Unfortunately keytool explicitly will not let you export from a trust store since they are of the opinion that PEM files do not support the concept of trusted certificate. So I would use the keystore of cer files instead.

  • From a cer:

    openssl x509 -inform der -in serverpub.cer -out serverpub.pem
    
  • From a keystore:

    keytool -importkeystore -srckeystore server.jks -destkeystore server.p12 -deststoretype PKCS12
    openssl pkcs12 -in server.p12 -nokeys -out server.cer.pem
    openssl pkcs12 -in server.p12 -nodes -nocerts -out server.key.pem
    

or just try

keytool -exportcert -alias myserverkeys -keystore serverpub.jks -rfc -file serverpub.pem

The following simple single line command will export the certificate to PEM format. Yes, you need openssl, keytool alone can't do this.

keytool -exportcert -alias <CERT-ALIAS> -keystore <KEYSTORE-FILE> | openssl x509 -inform DER >cert.pem
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!