title: Public key verification always returns "Signature does not match"
body: <p>I am trying to verify the public key of a certificate. The certificate has been imported into a keystore using this command:</p>
  
  <pre><code>keytool -importcert -file cert.cer -keystore kstore.jks -alias mycert -storepass changeit
  </code></pre>
  
  <p>This is the java code I use to verify the public key:</p>
  
  <pre><code>File keyStore = new File("kstore.jks");
  String keyStorePassword = "changeit";
  KeyStore ks = null;
  try {
     ks = KeyStore.getInstance("jks");
     ks.load(keyStore.toURI().toURL().openStream(), keyStorePassword.toCharArray());
  } catch (Exception e) {
     e.printStackTrace();
  } 
  
  try {
     Certificate cert = ks.getCertificate("mycert");
     PublicKey pk = cert.getPublicKey();
     cert.verify(pk);
     //cert.verify(pk, "SunRsaSign");
     System.out.println("Keys verified");
  } catch (Exception e) {
     e.printStackTrace();
  }
  </code></pre>
  
  <p>The exception I get is:</p>
  
  <pre><code>java.security.SignatureException: Signature does not match.
     at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:446)
     at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:389)
     at VerifyEBXMLSignature.runIt3(VerifyEBXMLSignature.java:62)
     at VerifyEBXMLSignature.main(VerifyEBXMLSignature.java:41)
  </code></pre>
  
  <p>The certificate contains a public key and I do not have access to the private key.
  Is it at all possible to verify the public key against this certificate that I import into a keystore? The public key comes from the certificate itself, so it should be correct.</p>
  
  <p>What more should I look for with the certificate?</p>
  
  <p>I just got some more iformation about the certificate: It is exported from the private key. Is there anything in that process that may have be done wrong?</p>