// JP opened flex table

Click to See Complete Forum and Search --> : Using CryptUnprotectData


shekar_raja
June 24th, 2008, 10:32 AM
Hi,

I am using CryptprotectData and CryptUnprotectData to store user credentials in the registry. The CryptprotectData & CryptUnprotectData work fine when I pass the OUT datablob from the CryptprotectData to the CryptUnprotectData API immediately.
Things are different when I save the result of the CryptprotectData into a registry and read it later to decrypt it. I think it has something to do with string format (WCHAR to BYTE*) but I seem to be converting it before passing it to the CryptUnprotectData API.

Here is my code -


WRReg.GetUserName(&szData);
DATA_BLOB DataEncrypted;
DataEncrypted.pbData = (BYTE*)(W2A(szData));
DataEncrypted.cbData = 2;
if(!CryptUnprotectData(&DataEncrypted,&pDescrOut,
NULL,NULL,NULL,CRYPTPROTECT_UI_FORBIDDEN,&DataBlob) )
return FALSE;


Any clues???

shekar_raja
June 25th, 2008, 11:35 AM
Do not store in the registry as a String. Using BINARY format to save the data in the registry resolved the issue.

TheCPUWizard
June 25th, 2008, 11:39 AM
Or Radix-64 it first....

//JP added flex table