RosettaCodeData/Task/Random-number-generator--device-/C/random-number-generator--device--4.c

24 lines
514 B
C
Raw Permalink Normal View History

2014-01-17 05:32:22 +00:00
#include <stdio.h> /* printf */
2013-04-10 23:57:08 -07:00
#include <windows.h>
2014-01-17 05:32:22 +00:00
#include <wincrypt.h> /* CryptAcquireContext, CryptGenRandom */
2013-04-10 23:57:08 -07:00
int
main()
{
2014-01-17 05:32:22 +00:00
HCRYPTPROV p;
ULONG i;
2013-04-10 23:57:08 -07:00
2014-01-17 05:32:22 +00:00
if (CryptAcquireContext(&p, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == FALSE) {
fputs("CryptAcquireContext failed.\n", stderr);
return 1;
}
if (CryptGenRandom(p, sizeof i, (BYTE *)&i) == FALSE) {
fputs("CryptGenRandom failed.\n", stderr);
return 1;
}
printf("%lu\n", i);
CryptReleaseContext(p, 0);
return 0;
2013-04-10 23:57:08 -07:00
}