title: BCrypt RSA private key import
body: <p>I want to import a private RSA pem key to BCryptImportKeyPair.
  I have no problem to import the public key but I don't know how the following structure and here especially cbPrime1/cbPrime2 for private key blob must be set:</p>
  
  <pre><code>pRsaBlob-&gt;Magic = BCRYPT_RSAPRIVATE_MAGIC;
  pRsaBlob-&gt;BitLength = pKey-&gt;rsapubkey.bitlen;
  pRsaBlob-&gt;cbPublicExp = cbExp;
  pRsaBlob-&gt;cbModulus = cbModulus;
  pRsaBlob-&gt;cbPrime1 = 0;
  pRsaBlob-&gt;cbPrime2 = 0;
  </code></pre>
  
  <p>The problem must be solved with BCrypt API because the code is inside a kernel mode driver.</p>
  
  <p>I fill at the moment this structure with my private blob:</p>
  
  <pre><code>struct PUBLIC_KEY_VALUES {
  BLOBHEADER blobheader;
  RSAPUBKEY rsapubkey;
  BYTE modulus[4096];};
  </code></pre>
  
  <p>I know that this also must be changed because the private blob does not match the 
  RSAPUBKEY.</p>
  
  <p>The data for the BLOB comes from the function:</p>
  
  <pre><code>   CryptDecodeObjectEx(X509_ASN_ENCODING|PKCS_7_ASN_ENCODING, PKCS_RSA_PRIVATE_KEY, privateKeyInfo-&gt;PrivateKey.pbData, privateKeyInfo-&gt;PrivateKey.cbData,
      CRYPT_DECODE_ALLOC_FLAG, NULL, &amp;keydata, &amp;keyLen);
  hr = HRESULT_FROM_WIN32(GetLastError());
  if (FAILED(hr)) goto cleanup;
  </code></pre>
  
  <p>I know that keydata is correct because I have no problem with them with the Wincrypt API.</p>