keytool error: java.lang.Exception: Certificate not imported, alias mykey already exists

Viewed 8721

I am trying to install a client certificate in my JVM to call a https soap service, but when running the keytool -import command I get the below error:

** keytool error: java.lang.Exception: Certificate not imported, alias already exists **

Here is the command I am using, please note I am using Java11

** C:\Softwares\java-11-openjdk-11.0.7.10-1.windows.redhat.x86_64\lib\security>keytool -import -keystore cacerts -file "C:\Softwares\client.certificate.pfx" **

Please suggest.

1 Answers

Every entry in the java keystore is identified by a key called alias. It has to be unique for a given keystore. If you don't provide one, the default value the keytool uses is mykey. Looks like there is an entry with mykey already in your keystore. All you have to do is give a name yourself. You can do this using the alias attribute, like this:

keytool -import -keystore cacerts -file "C:\Softwares\client.certificate.pfx" -alias third_party_ca

You can use any name as long as it is unique.

Related