Xpert Coder
New Member
- Joined
- Sep 24, 2012
- Messages
- 2
- Thread Author
- #1
Dear All,
I need some help regarding a strange issue with CryptUnprotectData function.
I have a C++ code that reads the database password from the registry and decrypts it using CryptUnprotectData. We have to deploy this application on a Windows 7 machine.
When I compile my code on Windows XP and run it on the test Windows 7 machine, it works absolutely fine. When I compile the same code on my laptop having Windows 7 and run it on the test Windows 7 machine, CryptUnprotectData fails with GetLastError() return '87'. If I run this application on my own laptop with Windows 7 on it, it again works fine probably because my laptop has a lot of things installed including Visual Studio and all the service packs etc.
I believe I have missed out installing some dependency on the test Windows 7 machine but I am unable to figure out what is that. What is it that's making the Windows XP compiled code running fine on the test machine and not the code that's compiled on Windows 7.
Here is the call to CryptUnprotectData in the code:
if (CryptUnprotectData(
&cipherText,
NULL,
NULL, // Optional entropy
NULL, // Reserved
NULL, // Optional PromptStruct
CRYPTPROTECT_UI_FORBIDDEN,
&plainText))
{
password.Append((char*)plainText.pbData, plainText.cbData);
}
else
{
char buff[256];
sprintf (buff, "CryptUnprotectData Error %d", GetLastError());
AfxMessageBox(buff);
}
Please suggest. Thanks in advance.
I need some help regarding a strange issue with CryptUnprotectData function.
I have a C++ code that reads the database password from the registry and decrypts it using CryptUnprotectData. We have to deploy this application on a Windows 7 machine.
When I compile my code on Windows XP and run it on the test Windows 7 machine, it works absolutely fine. When I compile the same code on my laptop having Windows 7 and run it on the test Windows 7 machine, CryptUnprotectData fails with GetLastError() return '87'. If I run this application on my own laptop with Windows 7 on it, it again works fine probably because my laptop has a lot of things installed including Visual Studio and all the service packs etc.
I believe I have missed out installing some dependency on the test Windows 7 machine but I am unable to figure out what is that. What is it that's making the Windows XP compiled code running fine on the test machine and not the code that's compiled on Windows 7.
Here is the call to CryptUnprotectData in the code:
if (CryptUnprotectData(
&cipherText,
NULL,
NULL, // Optional entropy
NULL, // Reserved
NULL, // Optional PromptStruct
CRYPTPROTECT_UI_FORBIDDEN,
&plainText))
{
password.Append((char*)plainText.pbData, plainText.cbData);
}
else
{
char buff[256];
sprintf (buff, "CryptUnprotectData Error %d", GetLastError());
AfxMessageBox(buff);
}
Please suggest. Thanks in advance.