Advertisement
Shokedbrain

crypto lab 1

Feb 14th, 2022
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <wincrypt.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void outError()
  8. {
  9.     const DWORD dw = GetLastError();
  10.     cout << dw << "\n";
  11. }
  12.  
  13. int main()
  14. {
  15.     HCRYPTPROV hCryptProv;
  16.     BYTE         pbData[16] = {}; // инициализируем переменную
  17.     if (CryptAcquireContext(
  18.         &hCryptProv,
  19.         nullptr,
  20.         MS_DEF_PROV,
  21.         PROV_RSA_FULL,
  22.         CRYPT_VERIFYCONTEXT))
  23.     {
  24.         if (CryptGenRandom(
  25.             hCryptProv,
  26.             8,
  27.             pbData))
  28.         {
  29.             CryptReleaseContext(hCryptProv, 0);
  30.             cout << "Random sequence generated\n";
  31.             for (const auto a : pbData)
  32.                 cout << a;
  33.             cout << "\n";
  34.         }
  35.         else
  36.         {
  37.             cout << "error with cryptgenrandom context\n";
  38.             CryptReleaseContext(hCryptProv, 0);
  39.             outError();
  40.         }
  41.     }
  42.     else
  43.     {
  44.         cout << "error with cryptacquire context\n";
  45.         outError();
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement