A pointer to the DATA_BLOB to be decrypted.
void main()
{
//First of all we need a string to encrypt
BYTE szTest[256] = "this string is for testing purposes";
//DataIn is for the unencrypted string and DataOut for the encrypted data.
DATA_BLOB DataIn = {0};
DATA_BLOB DataOut = {0};
//Convert the string to a pointer.
BYTE *pbDataInput = (BYTE *)szTest;
//Set pbData to the input string and specify how much memory it is using.
DataIn.pbData = pbDataInput;
DataIn.cbData = (DWORD) strlen((char *) pbDataInput) + 1;
//This will encrypt DataIn using CryptProtectData and save the result in DataOut.
//CryptProtectData encrypted data is only decryptable on the same computer as it was encrypted on.
EncryptData(&DataIn, &DataOut);
//Declaration of the recieving string.
char *szOut = new char[(DataOut.cbData * 2) + 1];
//Converts the content of DataOut to a string and saves it in szOut.
BlobToStr(&DataOut, szOut);
//Declaration of the DATA_BLOB structure that will recieve data from StrToBlob
//and the soon to be decrypted 'DecryptedData'
DATA_BLOB FromStrData = {0};
DATA_BLOB DecryptedData = {0};
//Converts szOut to a DATA_BLOB
StrToBlob(szOut, &FromStrData);
//Decrypt the contents of FromStrData
DecryptData(&FromStrData, &DecryptedData);
//original should contain "this string is for testing purposes"
BYTE * original = DecryptedData.pbData;
//Free the memory to prevent memory leaks.
LocalFree(DataOut.pbData);
LocalFree(DecryptedData.pbData);
delete szOut;
}