title: Adding a private key to X509Certificate2 - C#
body: <p>I'm new to 2WaySSL.</p>
  
  <p>What I'm trying to do:</p>
  
  <pre><code>1. Retrieve a Client certificate which is stored in a certificate store,
  I'm managing to do that by such code:
  
  
  
   certificates = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, false);
  </code></pre>
  
  <p>When attaching the certificate to the request, the authentication by the server fails,
  since I the certificate object does not contain the private key.</p>
  
  <p>I'm trying to find a way of associating the private key to the certificate (in c#),
  Once I'll retrieve the key from where it's stored.</p>
  
  <p>something like:</p>
  
  <pre><code>   certificate.PrivateKey = key;
  </code></pre>
  
  <p>But I found no easy way of either initiating the key object, or assigning it to the certificate without getting some exception, even when the key is null, I'm getting an access denied exception.</p>
  
  <p>Any help , especially followed by a code sample, would be appreciated.</p>