title: C# RSA equivalent code to the C++ Crypto API
body: <pre><code>DWORD nSize;
  LPBYTE lpData;
  HCRYPTKEY hPublicKey;
  
  
  nSize = ReadFromFile(lpszUserPublicKey, NULL);
  
  if(nSize == -1)
      return FALSE;
  
  lpData = new BYTE[nSize];
  
  ReadFromFile(lpszUserPublicKey, lpData);
  
  if(!CryptImportKey(hProv, lpData, nSize, NULL, 0, &amp;hPublicKey)) {
      delete lpData;
      return FALSE;
  }
  
  Erase(lpData, nSize);
  
  // Get the data size(&amp;nSize)
  if(!CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, NULL, &amp;nSize))
      return FALSE;
  
  lpData = new BYTE[nSize];
  
  CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, lpData, &amp;nSize);
  
  if(WriteToFile(lpszLicenseFile, lpData, nSize) == -1) {
      delete lpData;
      return FALSE;
  }
  
  delete lpData;
  
  return CryptDestroyKey(hPublicKey);
  </code></pre>
  
  <p>How would the above code be written in C#. I am particularily interested in the Crypto API calls. Note, the encryption method that is used is RSA</p>