swayz
swayz

Reputation: 65

CryptImportKey Windows 8.1 Using AES_256 PLAINTEXTKEYBLOB

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;

Works with Windows 7, this is not an exported key, but Fails on windows 8.1

If anyone has found a solution to this, it would help the entire internet.

Upvotes: 0

Views: 404

Answers (1)

swayz
swayz

Reputation: 65

dwDataLen param for CryptImportKey was set to 32, should be the total size of the byte array.

The issue is this works on windows 7 :\

sorry guys

Upvotes: 1

Related Questions