title: java.lang.Exception: Public keys in reply and keystore don't match
body: <p>I have to access a webservice hosted at port 443.Service provider has shared three certificate with us.</p>
  
  <ol>
  <li>ABCD.cer</li>
  <li>CA_Certificate.cer</li>
  <li>CCA_Certificate.cer</li>
  </ol>
  
  <p>I have to add them to keystore by creating a form chain for the SSL communication.I have followed below steps.</p>
  
  <ol>
  <li><p><code>keytool -keystore npci_keystore_test.jks -genkey -alias npci_client_testore</code> </p>
  
  <pre><code>   Result :- keystore npci_keystore_test.jks created.
  </code></pre></li>
  <li><p><code>keytool -import -keystore npci_keystore_test.jks -file CA_Certificate.cer -alias theCARoot</code></p>
  
  <pre><code>   Result :- certificate CA_Certificate.cer is added to keystore.
  </code></pre></li>
  <li><p><code>keytool -import -keystore npci_keystore_test.jks -file CCA_Certificate.cer -alias theCCARoot</code></p>
  
  <pre><code>   Result :- certificate CCA_Certificate.cer is added to keystore.
  </code></pre></li>
  <li><p><code>keytool -import -keystore npci_keystore_test.jks -file ABCD.cer -alias npci_client_testore</code></p>
  
  <p>At the step 4 i have below exception</p>
  
  <p>Enter keystore password:  (and when i enter password i have below exception)</p>
  
  <p><strong>keytool error: java.lang.Exception: Public keys in reply and keystore don't match</strong></p></li>
  </ol>
  
  <p>I have already done search in SO,but so far no luck.</p>
  
  <p>I am following below source to create the store and import certificate in it.
     <a href="http://docs.oracle.com/cd/E19509-01/820-3503/ggfgo/index.html" rel="noreferrer">JKS Keystore</a></p>
  
  <p><strong>EDIT:---</strong></p>
  
  <p>I have tested it by changing the import order of certificate,but no luck so far.</p>