Search code examples
javasslkeytooldigital-certificate

import .pem file in jre using keytool [Windows 7]


I have .pem file to access https url, but i am not able to import it in my local JDK, I am not sure which format should be accepted by keytool (.pem, .der, .cer, .jks, or .cer).

I found some solutions but that were using openssl,Import PEM into Java Key Store but i have to use keytool,

And also, When i execute "keytool -list" command on CMD, its giving me exception keytool error: java.lang.Exception: Keystore file does not exist:

can anyone give me steps to import a .pem file in jre

Thanks,


Solution

  • Do you mean, you want to import .pem file into JRE truststore? Truststore file is located in %JAVA_HOME%\jre\lib\security\cacerts. Default password is "changeit".

    Keytool accepts .pem certificate as well, so you don't need to convert it to another format. Simply execute the following import command,

    keytool -import -alias <PROVIDE_UNIQUE_CERTIFICATE_ALIAS_HERE> -file <PATH_TO_PEM_FILE> -keystore <JRE_TRUSTSTORE_FILE> -storepass <TRUSTSTORE_PASSWORD>
    

    And also, When i execute "keytool -list" command on CMD, its giving me exception keytool error: java.lang.Exception: Keystore file does not exist:

    You need to specify the keystore path as well as the keystore password,

    keytool -list -keystore <JRE_TRUSTSTORE_FILE> -storepass <TRUSTSTORE_PASSWORD>
    

    If you would like to know more about keytool commands, this following link could be your best buddy,

    https://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html