CryptImportKey Windows 8.1使用AES_256 PLAINTEXTKEYBLOB

时间:2016-04-21 16:37:42

标签: c++ windows encryption

context->last_error = NULL;

const BYTE key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// BLOBHEADER
    0x00, 0x00, 0x00, 0x00,//   Key size
    0x23, 0x31, 0xb1, 0x24, 0x7b, 0x15, 0xdf, 0xb0,//   AES KEY
    0xc9, 0x92, 0xaa, 0xc4, 0x2e, 0x02, 0x9b, 0x07,
    0xdf, 0x21, 0x12, 0x53, 0xba, 0x28, 0x77, 0xd2,
    0x99, 0x74, 0x96, 0xa4, 0x54, 0x54, 0x0d, 0xf1 }; 

BLOBHEADER* hdr = (BLOBHEADER*)key;
hdr->aiKeyAlg = CALG_AES_256;
hdr->bType = PLAINTEXTKEYBLOB;
hdr->bVersion = CUR_BLOB_VERSION;//default value
hdr->reserved = NULL;//reserved, default value

LPDWORD key_size = (LPDWORD)&key[sizeof(BLOBHEADER)];

//*(DWORD *)(key + 0x14) = 0;

*key_size = AES_KEY_SIZE_;

if (!CryptImportKey(context->context, key, 32, 0, CRYPT_EXPORTABLE, &context->aes_hKey))
{
    return context->last_error = GetLastError();
}
return context->last_error;

适用于Windows 7,这不是导出的密钥,但在Windows 8.1上失败

如果有人找到了解决方案,那将有助于整个互联网。

1 个答案:

答案 0 :(得分:1)

CryptImportKey的dwDataLen参数设置为32,应该是字节数组的总大小。

问题是这适用于Windows 7:\

对不起家伙