Search code examples
certificatepemjks

How to import .pem together with .key to a keystore (.jks)


I have a .pem certificate and a .key certificate file and i have to import them to a .jks keystore together, how do i achieve that?


Solution

  • I've found a soulution which includes exporting the .key and .pem certs to a .p12 file, and then importing that .p12 file to a java keystore (.jks).

    To export .pem and .key together to a .p12 use this command:

    openssl pkcs12 -export -in <path to .pem cert> -inkey <path to .key cert> -out <desired name of the .p12 file with the extension> -name <cert alias>
    

    Then, import the .p12 to the java keystore with this command:

    keytool -importkeystore -v -srckeystore <path to .p12 file> -srcstoretype PKCS12 -destkeystore <path to .jks> -deststoretype JCEKS