Export Java Keystore Certificate & Private Key to PEM

I always find Java Keystores a total ballache to work with, would rather manage individual PEM files any day of the week. If you need to export the contents for use with something else you can use the following commands:

Export from JKS to PKCS #12.
keytool -importkeystore -srckeystore oldkeystore.jks -destkeystore cert.p12 -deststoretype PKCS12 -srcalias tomcat -deststorepass -destkeypass

Export certificate.
openssl pkcs12 -in cert.p12 -nokeys -out cert.pem

Export unencrypted private key.
openssl pkcs12 -in cert.p12 -nodes -nocerts -out key.pem

You can leave a response, or trackback from your own site.

Leave a Reply