title: Load certificate keys into CngKey class for use with DiffieHellman (ECDiffieHellmanCng class)
body: <p>This is related to .NET / C#. Lets assume there is a certificate + private key (P521 ECC one) inside a PFX or a PKCS#12 file. We have loaded this certificate and it's private key into the Windows certificate store by installing it (either double clicking the PFX or running <code>certutil -f -p myPfxPassword -importPFX MY SomeEcCert.pfx</code>). I have noted that if the certificate is compatible (eg. p521 curve), it is automatically installed as a CNG certificate/key.</p>
  
  <p>Now, how can I load the private key into a CngKey so I can then use it inside the <code>ECDiffieHellmanCng</code> class? I would also like to load the X509 (CNG) certificate to read it's serial #, issuer, common name etc for some bookkeeping. </p>
  
  <pre><code>var myCngKey = SomehowLoadTheCngKey("my ecc certificate"); // &lt;== ??
  var myDH = new ECDiffieHellmanCng(myCngKey);
  </code></pre>