Hi all,
I am writing a test application for Microsoft CryptoAPI. I want to export the secret key of one party using the public key of the second party, and then import that secret key as the second party's secret key (this sets up a shared secret key for communication). Here is my code:
if(!CryptExportKey(encryptT->hSymKey, decryptT->hPubKey, SIMPLEBLOB, 0, keyExBuf, &bufLen)) {
FormattedDebugPrint(NULL, GetLastError(), "could not export secret key", TRUE);
return -1;
}
if(!CryptImportKey(decryptT->hCryptProv, keyExBuf, bufLen, decryptT->hPubKey, 0, &(decryptT->hSymKey))) {
FormattedDebugPrint(NULL, GetLastError(), "could not import secret key", TRUE);
return -1;
}
And this gives the error:
80090001: Bad UID.
The public keypair is being generated for both encryptT and decryptT (sender, receiver) by calling:
CryptGenKey(encryptT->hCryptProv, CALG_RSA_KEYX, CRYPT_EXPORTABLE, &(encryptT->hPubKey))
Any idea what could be causing the error?
Thanks,