I have a public key and I want to use it to encrypt a piece of data. I'm trying to import the public key in order to use it, but CryptImportKey gives me an 'invalic parameter' error.
What's the problem?
Here's my code:
if( !CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) )
{
/*
* Print error and return
*/
}
pblob->header->bType = PUBLICKEYBLOB;
pblob->header->aiKeyAlg = CALG_AES_128;
pblob->header->bVersion = CUR_BLOB_VERSION;
pblob->header->reserved = 0;
pblob->key_len = key_len;
memcpy(pblob->key, key , key_len);
if( !CryptImportKey( &hProv,
(LPCBYTE)pblob,
sizeof(*pblob),
0,
CRYPT_EXPORTABLE,
&hKey ) )
{
// Print error and return
}