-
-
Save roninhack/03090e0565db8bb34f0de0094bba8381 to your computer and use it in GitHub Desktop.
Sample code for the CryptGenRandom function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <windows.h> | |
#pragma comment(lib, "advapi32.lib") | |
int main() | |
{ | |
HCRYPTPROV hProvider = 0; | |
if (!::CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) | |
return 1; | |
const DWORD dwLength = 8; | |
BYTE pbBuffer[dwLength] = {}; | |
if (!::CryptGenRandom(hProvider, dwLength, pbBuffer)) | |
{ | |
::CryptReleaseContext(hProvider, 0); | |
return 1; | |
} | |
for (DWORD i = 0; i < dwLength; ++i) | |
std::cout << std::hex << static_cast<unsigned int>(pbBuffer[i]) << std::endl; | |
if (!::CryptReleaseContext(hProvider, 0)) | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment