我正在调用BCryptDecrypt
返回错误的函数。我收到错误 120 using getlasterror
,这意味着此系统不支持此功能(在 msdn 中)。
status = BCryptDecrypt( hKey, pbInput, cbInput, NULL, NULL, sizeof(DWORD), NULL, 0, &pcbResult, BCRYPT_BLOCK_PADDING);
pbInput
是指向包含要解密的数据的地址的指针,cbInput
是文件的长度,pcbResult
将获得输出文件(解密的数据)的大小。BCryptEncrypt
工作正常但BCryptDecryptis
不工作。
谁能帮帮我?与解密相关的几行代码:
状态 = BCryptOpenAlgorithmProvider(&hAlgorithm , BCRYPT_AES_ALGORITHM , NULL , 0); 如果(!NT_SUCCESS(状态)){返回;}
DWORD cbKey = 0;
DWORD cbData =0;
status = BCryptSetProperty(hAlgorithm , BCRYPT_CHAINING_MODE , (PBYTE)BCRYPT_CHAIN_MODE_ECB , sizeof(BCRYPT_CHAIN_MODE_ECB) , 0);
if (!NT_SUCCESS(status))
{
return;
}
status = BCryptGetProperty(hAlgorithm,
BCRYPT_OBJECT_LENGTH,
(LPBYTE)&cbData,
sizeof(DWORD),
&cbKey,
0);
LPBYTE pbKey = (BYTE*)HeapAlloc(GetProcessHeap() , 0 , cbData);
LPCSTR szpwd = (LPCSTR)Getpwd();
BCRYPT_KEY_HANDLE hKey = NULL;
status = BCryptGenerateSymmetricKey(hAlgorithm,
&hKey,
pbKey,
cbData,
(PUCHAR)szpwd,
(ULONG)strlen(szpwd),
0);
if (!NT_SUCCESS(status))
{
if(hAlgorithm)
{
BCryptCloseAlgorithmProvider(hAlgorithm,0);
}
if(pbKey)
{
HeapFree(GetProcessHeap(), 0, pbKey);
}
return;
}
DWORD pcbResult = 0;
status = BCryptDecrypt( hKey,
pbInput,
cbInput,
NULL,
NULL,
sizeof(DWORD),
NULL,
0,
&pcbResult,
BCRYPT_BLOCK_PADDING);
DWORD cbError = GetLastError();
if(cbError != 0)
{
LPCSTR messageBuffer = NULL;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, cbError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);