title: How to get the private key from a separate file?
body: <p>I have an Apache (xampp/wamp) server that provides a SSL connection on port 443.
  It uses two certificate files: server.cert and server.key when the latter conains the private key.</p>
  
  <p>I have another server configured to listen to requests on port 843 (flash policy stuff) and response to a certain request with some text reply written in C# which runs separately.</p>
  
  <p>In order to achieve SSL connectivity, i use a flex object called SecureSocket which allowes that, however, it uses the original servers certificate in order to encrypt the request.</p>
  
  <p>My goal is to teach my 843 C# server to decrypt the sent data and encrypt the reply and for this i'm using the X509Certificate object in C#.</p>
  
  <p>However, since the pub and priv keys are on different files, i'm getting FALSE on the following:</p>
  
  <pre><code>string text = System.IO.File.ReadAllText(@"C:\xampp\apache\conf\ssl.crt\server.crt");
  UTF8Encoding encoding = new System.Text.UTF8Encoding();
  byte[] byteCert = encoding.GetBytes(text);
  X509Certificate2 uberCert = new X509Certificate2();
  uberCert.Import(byteCert);
  Console.WriteLine("Has privateKey:" + uberCert.HasPrivateKey.ToString());
  Console.WriteLine("PrivateKey: \n" + uberCert.PrivateKey);
  </code></pre>
  
  <p>Obviously, the False on uberCert.HasPrivateKey comes from the fact that the private key is on a different file, so my questions are: </p>
  
  <p>1.How can i read the private key using the X509CErtificate2 object?
  2.How can i use the public key in order to decrypt the received message and how to re-encrypt it with the private key (in order to send the encrypted response back) ?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Mike.</p>