title: Issues in importing a certificate to Spring
body: <p>I want to hit the REST endpoints of a Server, say xyz.com. They have provided certificates in PEM format which I should be including in my application while connecting to their endpoints.</p>
  
  <p>My application is written on Spring Framework and I need to convert PEM to P12 format as Spring won't accept PEM. This is how I convert:</p>
  
  <pre><code>openssl pkcs12 -export -out certificate.p12 -inkey private.pem -in server_cert.pem
  </code></pre>
  
  <p>Where,</p>
  
  <blockquote>
    <p>certificate.p12 = resultant p12 file</p>
    
    <p>private.pem = private key</p>
    
    <p>server_cert.pem = certificate files of the server</p>
  </blockquote>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>No certificate matches private key.</p>
  </blockquote>
  
  <p>Now my questions:</p>
  
  <ol>
  <li>Whose private key should be used to generate the P12 file from the PEM file? </li>
  <li>If the private key of <strong>client</strong> is used to generate p12, how could it possibly match with the certificate (error message becomes obvious)?</li>
  <li>Why would I need <strong><em>my</em></strong> private key to communicate with the server? As per my understanding, during an SSL session, the private key of the client doesn't come into the picture. Or is my understanding wrong?</li>
  <li>If the private key of the <strong>server</strong> is used to generate p12, why would they share it?</li>
  </ol>
  
  <p>I'm a novice and therefore any links/suggested-reading/sources/answers are welcome.</p>