#include <windows.h>
#include <wincrypt.h>
// https://www.dllhook.com
BOOL GenerateRandomData(LPVOID buffer, DWORD dwLen)
{
HCRYPTPROV hProv = 0;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
return FALSE;
}
BOOL result = CryptGenRandom(hProv, dwLen, (BYTE*)buffer);
CryptReleaseContext(hProv, 0);
return result;
}
void TestCryptGenRandom()
{
const int len = 16;
BYTE buffer[len];
if (GenerateRandomData(buffer, len))
{
printf("Random data: ");
for (int i = 0; i < len; i++)
{
printf("%02X ", buffer[i]);
}
printf("\n");
}
}
int main()
{
TestCryptGenRandom();
}
已有1247位网友发表了看法:
发表评论