CryptStringToBinary在正确的数据上失败,ERROR_INVALID_DATA [英] CryptStringToBinary fails with ERROR_INVALID_DATA on correct data
问题描述
数据为" 158e8106901649224dba1ee6944d4f6b4109fdbd "。我用CRYPT_STRING_HEXRAW和CRYPT_STRING_HEX_ANY调用了该函数,指定
cchString 作为实际数据长度或0(因为它是零终止的),试图用* <调用函数em> pbBinary == 0(为缓冲区获取一定量的内存),使数据大写,但无论如何都失败了!
The data is "158e8106901649224dba1ee6944d4f6b4109fdbd". I called the function with CRYPT_STRING_HEXRAW and CRYPT_STRING_HEX_ANY, specified cchString as actual data length or as 0 (because it is zero-terminated), tried to call the function with *pbBinary==0 (to get an amount of memory for buffer), made the data uppercase, but it anyway fails!
它出了什么问题?
如果我跌倒,我将在去天堂的路上出现
If I fall I will arise on my way to paradise
推荐答案
我不确切地知道你是如何调用该函数的,但以下所有内容在Win 7上都取得了成功 -
I don't know exactly how you're calling the function, but all the following returned success on Win 7 -
TCHAR szHex[] = _T("158e8106901649224dba1ee6944d4f6b4109fdbd");
DWORD cbBinary = 0, dwSkip = 0, dwFlags = 0;
if (CryptStringToBinary(szHex, _tcslen(szHex), CRYPT_STRING_HEX_ANY, NULL, &cbBinary, &dwSkip, &dwFlags))
printf_s("Success, buffer needed %u bytes, flags used %#0.8x\n", cbBinary, dwFlags);
else
printf_s("CryptStringToBinary failed\n");
cbBinary = 0;
dwFlags = 0;
if (CryptStringToBinary(szHex, _tcslen(szHex), CRYPT_STRING_HEXRAW, NULL, &cbBinary, &dwSkip, &dwFlags))
printf_s("Success, buffer needed %u bytes, flags used %#0.8x\n", cbBinary, dwFlags);
else
printf_s("CryptStringToBinary failed\n");
cbBinary = 0;
dwFlags = 0;
if (CryptStringToBinary(szHex, 0, CRYPT_STRING_HEX_ANY, NULL, &cbBinary, &dwSkip, &dwFlags))
printf_s("Success, buffer needed %u bytes, flags used %#0.8x\n", cbBinary, dwFlags);
else
printf_s("CryptStringToBinary failed\n");
cbBinary = 0;
dwFlags = 0;
if (CryptStringToBinary(szHex, 0, CRYPT_STRING_HEXRAW, NULL, &cbBinary, &dwSkip, &dwFlags))
printf_s("Success, buffer needed %u bytes, flags used %#0.8x\n", cbBinary, dwFlags);
else
printf_s("CryptStringToBinary failed\n");
这篇关于CryptStringToBinary在正确的数据上失败,ERROR_INVALID_DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!