I'm having trouble using the Windows cryptography API to encode/decode AES-128 blocks.
It seems like the system is geared around first generating a hash, then using that hash to set the key, i.e. CryptCreateHash
, CryptHashData
, CryptDeriveKey
. But there is no indication on how to use a null-hash and instead just use raw data to initialize the key.
Specifically I want to use a fixed, 128-bit key, with a fixed, 128-bit IV that is shared to each side of a link through a secure channel.
Side-note: This is the only way I could find how to make a PROV_RSA_AES
instead of a PROV_RSA_FULL
.
If I use the following sequence to try to set the key, I get error 8009000a
CryptAcquireContext( &m_hCryptProv, 0, "Microsoft Enhanced RSA and AES Cryptographic Provider", PROV_RSA_AES, CRYPT_VERIFYCONTEXT );
CryptGenKey( m_hCryptProv, CALG_AES_128, 0, &m_hCryptKey );
CryptSetKeyParam( m_hCryptKey, KP_IV, IV, 0 );
CryptSetKeyParam( m_hCryptKey, KP_KEYVAL, key, 0 ) << FAIL