Import Java Trusted Certificate to JRE

39,004

A couple of examples on how to do this using "keytool"

The second link here has an example batch file:

@echo off
echo
echo This will import an X.509 SSL certificate into the keystore for the JVM
specified
echo
echo Press Control+C to abort.
pause
SETLOCAL

rem -------------------------------------------------
rem 1) Set the path to you JVM here
rem -------------------------------------------------
set JAVA_HOME=C:\j2sdk1.4.2_05

rem -------------------------------------------------
rem 2) SET THE CERTIFICATE NAME AND ALIAS HERE
rem -------------------------------------------------
set CERT_NAME=mycert.cer
set CERT_ALIAS=mycert

rem -------------------------------------------------
rem 3) SET THE KEYTOOL PASSWORD HERE
rem -------------------------------------------------
set KEYTOOL_PASS=changeit

rem -------------------------------------------------
rem DO NOT EDIT BELOW THIS LINE
rem -------------------------------------------------
set JAVA_SECURITY=%JAVA_HOME%\jre\lib\security
set CERT=%JAVA_SECURITY%\%CERT_NAME%
%JAVA_HOME%\jre\bin\keytool -import -trustcacerts -keystore %JAVA_SECURITY%\cacerts
-storepass %KEYTOOL_PASS% -noprompt -alias %CERT_ALIAS% -file %CERT%
ENDLOCAL
pause

Which part are you having trouble understanding? Is there a particular section that doesn't make sense? Do you need help with the batch file? Where, specifically, are you getting stuck? Perhaps I can help more specifically.

Share:
39,004

Related videos on Youtube

Zalastax
Author by

Zalastax

Updated on September 18, 2022

Comments

  • Zalastax
    Zalastax over 1 year

    I need to install a certificate from a Java app to a lot of people. I want to use a one click program or batch file to import it as a Trusted Certificate(in Control Panel->Security->Certificate). Then they won't need to press always allow first time they use the application.

    I have extracted the needed certificate as both a .csr and as a .cer (the .csr via Control Panel and the .cer via keytool). Now I need to get one of them back without any clicking in menus.

    I don't really understand the documentation of importing .cer with keytool and would like an example. Or are there an easier way than using keytool?

  • Zalastax
    Zalastax almost 13 years
    Thanks for the Googling :( As I said I had problems understanding how to get it in.
  • jefflunt
    jefflunt almost 13 years
    I've updated my answer.
  • Zalastax
    Zalastax almost 13 years
    On the second page I think the main problem was the readability of the page. I will see if I can get it all trought
  • Zalastax
    Zalastax almost 13 years
    The problem I have now is that I don't know the password. What should enter? I didn't do anything with the certificate after I got it out from keytool.
  • Zalastax
    Zalastax almost 13 years
    I found the password out by looking in the batch file. But nothing seems to happen. After entering the right password I don't get any errors but cmd don't seem to do anything either. The certificate don't seem to be there either.
  • Zalastax
    Zalastax almost 13 years
    It seems like that batch isn't what I was looking for. It was for some sort of developing and didn't seem to work for my JRE.