Import pem certificate into Java KeyStore (jks)

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

To achieve that we convert the certificate into a binary cert that can be imported by the Java keytool.

First, convert your certificate in a DER format :

openssl x509 -outform der -in certificate.pem -out certificate.der

And after that, import it in the keystore :

keytool -import -alias your-alias -keystore cacerts -file certificate.der