title: SSL with private key on an HSM
body: <p>I have a client-server architecture in my application that uses SSL.  Currently, the private key is stored in CAPI's key store location.  For security reasons, I'd like to store the key in a safer place, ideally a hardware signing module (HSM) that is built for this purpose.  Unfortunately, with the private key stored on such a device, I can't figure out how to use it in my application.</p>
  
  <p>On the server, I am simply using the <code>SslStream</code> class and the <code>AuthenticateAsServer(...)</code> call.  This method takes an <code>X509Certificate</code> object that has its private key loaded, but since the private key is stored in a secure (e.g. non exportable) location on the HSM, I don't know how to do this.</p>
  
  <p>On the client, I am using an <code>HttpWebRequest</code> object and then using the <code>ClientCertificates</code> property to add my client authentication certificate, but I have the same problem here: how do I get the private key?</p>
  
  <p>I know there are some HSMs that act as SSL accelerators but I don't really need an accelerator.  Also, these products tend to have special integration with web servers such as IIS and Apache which I'm not using.</p>
  
  <p>Any ideas?  The only thing I can think of would be to write my own SSL library that would allow me to hand off the signing portion of the transaction to the HSM, but this seems like a huge amount of work.</p>