Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed some bugs in the coding examples

...

Code Block
bgColor#ccccff
langc
#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);
    }
  }
}

...