title: How to import .cer public key into java trust store?
body: <p>Here is the command that I am using to import the public key into my trust store. </p>
  
  <pre><code>$ keytool -import -trustcacerts -file dev.cer -alias my_alias -keystore truststore.jks -storepass mypass -v
  </code></pre>
  
  <p>The output that I get is:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>The content of the <code>dev.cer</code> file looks like:</p>
  
  <pre><code>-----BEGIN PUBLIC KEY-----
  ... encoded text ...
  -----END PUBLIC KEY-----
  </code></pre>
  
  <p>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.</p>
  
  <p>Any help will be greatly appreciated.</p>