title: CryptExportKey: how to export private key from PKCS#12 store?
body: <p>I need to export public and private RSA key from certificate, stored in <code>PKCS#12</code> format, on Windows.</p>
  
  <p>I can open certificate store with <code>CertOpenStore()</code>, then find certificate with <code>CertFindCertificateInStore()</code> and acquire private key with <code>CryptAcquireCertificatePrivateKey()</code>. </p>
  
  <p>It works Ok. Then I extract user key with <code>CryptGetUserKey()</code> It works too.</p>
  
  <p>But <code>CryptExportKey()</code> with blob type <code>PRIVATEKEYBLOB</code> fails.
  <code>CryptSetKeyParam()</code> with <code>KP_PERMISSIONS</code> and set permission <code>CRYPT_EXPORT</code> also fails.</p>
  
  <p>How could I get all RSA key pair parameters in such case?</p>
  
  <p>All examples use <code>CryptGenKey()</code> to create and THEN export key, but I need to export existing key pair to simple binary form.</p>