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, &hPublicKey)) {
delete lpData;
return FALSE;
}
Erase(lpData, nSize);
// Get the data size(&nSize)
if(!CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, NULL, &nSize))
return FALSE;
lpData = new BYTE[nSize];
CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, lpData, &nSize);
if(WriteToFile(lpszLicenseFile, lpData, nSize) == -1) {
delete lpData;
return FALSE;
}
delete lpData;
return CryptDestroyKey(hPublicKey);
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