Ihor M.
Ihor M.

Reputation: 3148

How to import .cer public key into java trust store?

Here is the command that I am using to import the public key into my trust store.

$ keytool -import -trustcacerts -file dev.cer -alias my_alias -keystore truststore.jks -storepass mypass -v

The output that I get is:

keytool error: java.lang.Exception: Input not an X.509 certificate
java.lang.Exception: Input not an X.509 certificate
        at sun.security.tools.keytool.Main.addTrustedCert(Main.java:2652)
        at sun.security.tools.keytool.Main.doCommands(Main.java:1006)
        at sun.security.tools.keytool.Main.run(Main.java:340)
        at sun.security.tools.keytool.Main.main(Main.java:333)

The content of the dev.cer file looks like:

-----BEGIN PUBLIC KEY-----
... encoded text ...
-----END PUBLIC KEY-----

One more thing worth mentioning that this certificate was generated on Windows running machine and I want to import it in the Linux environemnt. Maybe it has something to do with the special characters.

Any help will be greatly appreciated.

Upvotes: 1

Views: 4959

Answers (1)

Ihor M.
Ihor M.

Reputation: 3148

The reason of the keytool error: java.lang.Exception: Input not an X.509 certificate is caused by the fact that instead of importing a certificate, there was an attempt to import a public key (even though the file extension is .cer , the header -----BEGIN PUBLIC KEY----- and the footer -----END PUBLIC KEY----- indicate that the file doesn't contain a valid certificate, but the public key only). Terms public certificate and public key at times by mistake are used interchangeably.

Upvotes: 2

Related Questions