Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <wincrypt.h>
- #include <iostream>
- using namespace std;
- void outError()
- {
- const DWORD dw = GetLastError();
- cout << dw << "\n";
- }
- int main()
- {
- HCRYPTPROV hCryptProv;
- BYTE pbData[16] = {}; // инициализируем переменную
- if (CryptAcquireContext(
- &hCryptProv,
- nullptr,
- MS_DEF_PROV,
- PROV_RSA_FULL,
- CRYPT_VERIFYCONTEXT))
- {
- if (CryptGenRandom(
- hCryptProv,
- 8,
- pbData))
- {
- CryptReleaseContext(hCryptProv, 0);
- cout << "Random sequence generated\n";
- for (const auto a : pbData)
- cout << a;
- cout << "\n";
- }
- else
- {
- cout << "error with cryptgenrandom context\n";
- CryptReleaseContext(hCryptProv, 0);
- outError();
- }
- }
- else
- {
- cout << "error with cryptacquire context\n";
- outError();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement