...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <Windows.h> #include <wincrypt.h> #include <stdio.h> void func(void) { HCRYPTPROV hCryptProv; /* union stores the random number generated by CryptGenRandom() */ union { BYTE bs[sizeof(long int)]; long int li; } rand_buf; /* An example of instantiating the CSP */ if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) { printf("CryptAcquireContext succeeded.\n"); } else { printf("Error during CryptAcquireContext!\n"); } for (int i = 0; i < 10; ++i) { if (!CryptGenRandom(hCryptProv, sizeof(rand_buf), (BYTE *) &rand_buf)) { printf("Error\n"); } else { printf("%ld, ", rand_buf.li); } } } |
...