1

我有一个问题:当我尝试生成 AES 密钥 128 长度时,CryptGenKey我有数据泄漏?

下面的代码:

void GeKey(HCRYPTKEY hKey, HCRYPTPROV hProvs)
{
    DWORD len_iv = 0;

    if (!CryptGenKey(hProvs, CALG_AES_128, CRYPT_EXPORTABLE, &hKey))
    {
        ExitProcess(0);
    }

    if (!CryptExportKey(hKey, NULL, PLAINTEXTKEYBLOB, NULL, NULL, &len_iv))
    {
        ExitProcess(0);
    }

    unsigned char* aes_key_dec = new unsigned char[len_iv];

    if (!CryptExportKey(hKey, NULL, PLAINTEXTKEYBLOB, NULL, aes_key_dec, &len_iv))
    {
        ExitProcess(0);
    }

    for (int i = 0; i < len_iv; i++)
    {
        printf("%c", aes_key_dec[i]);
    }
    printf("\n\n");

    delete[] aes_key_dec;
}

delete[] aes_key_dec;无法帮助我解决这个问题。怎么了 :/

4

0 回答 0