title: 3DES with .cer public key?
body: <p>I'm no crypto expert, but as I understand it, 3DES is a symmetric encryption algorithm, which means it doesnt use public/private keys.</p>
  
  <p>Nevertheless, I have been tasked with encrypting data using a public key, (specifically, a .CER file).
  If you ignore the whole symmetric/asymmetric thang, I should just be able to use the key data from the public key as the TripleDES key.
  However, I'm having difficulty extracting the key bytes from the .CER file.
  This is the code as it stands..</p>
  
  <pre><code>TripleDESCryptoServiceProvider cryptoProvider = new TripleDESCryptoServiceProvider();
  X509Certificate2 cert = new X509Certificate2(@"c:\temp\whatever.cer");
  cryptoProvider.Key = cert.PublicKey.Key.
  </code></pre>
  
  <p>The simplest method I can find to extract the raw key bytes from the certificate is ToXmlString(bool), and then doing some hacky substringing upon the returned string.
  However, this seems so hackish I feel I must be missing a simpler, more obvious way to do it.</p>
  
  <p>Am I missing a simpler way to use a .cer file to provide the key data to the C# 3DES crypto class, or is hacking it out of the certificate xml string really the best way to go about this?</p>