Ssl – Generate SSL certificate using Keytool

keytoolopensslsslssl-certificate

I have a question about SSL certificates.

I use Openssl to generate the certificate: I followed this tutorial. My goal is to generate:

  • .crt
  • .key
  • .pem

Is possible to obtain the same files using keytool?

Best Answer

This StackOverflow question outlines obtaining certificates from a Java keystore like you would generate with keytool in PEM and PKCS#12 format. In short:

$ keytool -importkeystore -srckeystore srckeystore.jks -destkeystore dest.p12 -srcstoretype jks -deststoretype pkcs12

$ openssl pkcs12 -in dest.p12 -out dest.pem

You will end up with your keys and certs in PEM format, as well as a PKCS#12 copy of the keystore. Note that this still requires using openSSL to convert the PKCS#12 keystore to .PEM format. If you export directly from JKS to PEM you will not get the private keys out of the store.