我是 C++ 的新手,昨天开始学习 wincrypt。我写了这段代码,
#pragma comment(lib, "crypt32.lib")
#include <iostream>
#include <windows.h>
#include <wincrypt.h> // CryptoAPI definitions
using namespace std;
int main()
{
string encMe = "password";
HCRYPTKEY hKey;
HCRYPTPROV hProv;
PBYTE pbBuffer = NULL;
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_NEWKEYSET | CRYPT_VERIFYCONTEXT);
//cout << hex << GetLastError() << endl; DEBUG
if(NTE_EXISTS == GetLastError())
{
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT);
}
else if(0 == GetLastError())
{
cout << "Succes1" << endl;
}
CryptGenKey(hProv, CALG_AES_256, CRYPT_EXPORTABLE, &hKey);
if(GetLastError() == 0)
{
cout << "Succes2" << endl;
cout << hKey << endl;
}
cout << CryptEncrypt(hKey, 0, TRUE, 0, NULL, NULL, 1000) << endl;
cout << GetLastError();
}
我被困在 CryptEncrypt 函数上。我阅读了 MSDN 页面,在“hKey, 0, True, 0”之后没有理解任何内容。例如,向我解释一下“指向包含要加密的明文的缓冲区的指针”是什么。先感谢您!