BAD_UID error while exporting key in CryptoAPI
Posted
by mindthief
on Stack Overflow
See other posts from Stack Overflow
or by mindthief
Published on 2010-04-23T04:06:57Z
Indexed on
2010/04/23
4:13 UTC
Read the original article
Hit count: 574
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,
© Stack Overflow or respective owner