CryptImportKey() is returning NTE_BAD_DATA
- From: Esha <iimeandmyself@xxxxxxxxx>
- Date: Thu, 29 Oct 2009 15:01:16 +0530
I'm trying to use CryptoAPI on XP SP3 to authenticate a smart card. I have a public key which is supplied by the smart card vendor. I need to use this to authenticate with the application running in the smart card. I am supposed to use 3DES as the algo. I'm doing the following steps -
1. Acquire context for the CSP
2. Create a public key blob with the public key i have
3. Call CryptImportKey() with this blob. - Here I get an error NTE_BAD_DATA.
What is the problem with my code ?
Please suggest me the steps involved in using 3DES encryption when a public is already available.
My code snippet is
-------------------------------------------------------------------------------
TEST_PUBLICKEYBLOB pubkeyblob;
BYTE Testkey[255] = {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
DWORD TestkeyLen = 24;
if(!CryptAcquireContext(&hCryptProv, NULL, NULL,
PROV_RSA_FULL, CRYPT_NEWKEYSET))
{
printf("\nCryptAcquireContext: INVALID context, ERROR 0x%x",
GetLastError());
return FALSE;
}
pubkeyblob.hdr.bType = PUBLICKEYBLOB;
pubkeyblob.hdr.bVersion = 0x02;
pubkeyblob.hdr.reserved = 0;
pubkeyblob.hdr.aiKeyAlg = CALG_3DES;
pubkeyblob.pubkey.magic = 0x31415352;
pubkeyblob.pubkey.bitlen = 24;
pubkeyblob.pubkey.pubexp = 0;
memcpy((pubkeyblob.modulus),Testkey,TestkeyLen);
printf("\nKey: ");
for(i = 0; i < PassKeyLen; i++)
{
printf("0x%x ",pubkeyblob.modulus[i]);
}
printf("\n");
if(!CryptImportKey(hCryptProv, (BYTE *)&pubkeyblob,
sizeof(TEST_PUBLICKEYBLOB), 0, 0, &ctx->hKey))
{
printf("\nError %x during CryptImportKey!\n", GetLastError());
}
.
- Follow-Ups:
- RE: CryptImportKey() is returning NTE_BAD_DATA
- From: Mounir IDRASSI
- RE: CryptImportKey() is returning NTE_BAD_DATA
- Prev by Date: RE: FuncReturnhWnd returning ERROR_INVALID_PARAMETER
- Next by Date: RE: CryptImportKey() is returning NTE_BAD_DATA
- Previous by thread: Administrator of a remote machine?
- Next by thread: RE: CryptImportKey() is returning NTE_BAD_DATA
- Index(es):
Relevant Pages
|