抱歉,我不能为此使用单独的类,我尝试构建以下代码并在循环中从外部调用时获得相同的输出。
unsigned int crypt_rand()
{
HCRYPTPROV hProvider = 0;
const DWORD dwLength = sizeof(unsigned int);
unsigned int pbBuffer[dwLength] = {};
if (!::CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
return 1;
if (!::CryptGenRandom(hProvider, sizeof(unsigned int), reinterpret_cast<PBYTE>(&pbBuffer)))
{
::CryptReleaseContext(hProvider, 0);
return 1;
}
if (!::CryptReleaseContext(hProvider, 0))
return 1;
return (unsigned int)pbBuffer;
}
如果我每次都从循环中调用这个函数,得到相同的输出。在这个方法中,我能提供什么像时间一样的输入吗?你能帮我吗?
for (DWORD i = 0; i < 5; ++i)
{
rand_no = crypt_rand();
std::cout << "windows::"<<i<<"::"<<rand_no<< std::endl;
}
输出是
windows::0::4519964
windows::1::4519964
windows::2::4519964
windows::3::4519964
windows::4::4519964