#include <windows.h>
#include <wincrypt.h>

// https://www.dllhook.com
BOOL GenerateRandomData(LPVOID buffer, DWORD dwLen)
{
    HCRYPTPROV hProv = 0;
    if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
    {
        return FALSE;
    }

    BOOL result = CryptGenRandom(hProv, dwLen, (BYTE*)buffer);

    CryptReleaseContext(hProv, 0);
    return result;
}

void TestCryptGenRandom()
{
    const int len = 16;
    BYTE buffer[len];

    if (GenerateRandomData(buffer, len))
    {
        printf("Random data: ");
        for (int i = 0; i < len; i++)
        {
            printf("%02X ", buffer[i]);
        }
        printf("\n");
    }
}

int main()
{
    TestCryptGenRandom();
}

你可能感兴趣的文章

评论区

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。