if(!CryptAcquireContext
(&hProv,"_hprvkey1",MS_ENHANCED_PROV,PROV_RSA_FULL,0 /*CRYP
T_MACHINE_KEYSET*/) && !CryptAcquireContext
(&hProv,"_hprvkey1",MS_ENHANCED_PROV,PROV_RSA_FULL,CRYPT_NE
WKEYSET /*| CRYPT_MACHINE_KEYSET*/))
{
ResCode = -1;
}
// Open key from file
RSAPubKey1024 PubKey;
dwLen=sizeof(RSAPubKey1024);
CFile dskFile;
if(!dskFile.Open(KeyFileName.c_str
(),CFile::modeRead))
{
ResCode = -10034;
goto Ennd;
}
// Read
if(dskFile.Read(&PubKey,dwLen) != dwLen)
{
ResCode = -101;
goto Ennd;
}
dskFile.Close();
// Import key
if(!CryptImportKey(hProv,(unsigned char *)
&PubKey,dwLen,0,0 ,&wrkKey))
{
DWORD Err = GetLastError();
ResCode = -102;
goto Ennd;
}
// Create HASH
if(!CryptCreateHash(hProv,CALG_MD5,0,0,&hHash))
{
ResCode = -103;
goto Ennd;
}
// Read 3DES key from file
if (Data->Read(&EncryptedPartHeader, sizeof
(EncryptedPartHeader)) != sizeof(EncryptedPartHeader))
{
ResCode = -104;
goto Ennd;
}
// Import 3DES key
//********* here function return NTE_BAD_KEY error code
if(!CryptImportKey(hProv,(BYTE *)
&EncryptedPartHeader.kb,EncryptedPartHeader.KeyLen/*sizeof
(RSA1024KeyExchBLOB)*/,wrkKey,0,&h3DESKey))
{
DWORD Err = GetLastError();
ResCode = -105;
goto Ennd;
}
In the first CryptImportKey call did you import a PRIVATEKEYBLOB ? I am
guessing you imported a PUBLICKEYBLOB and hence it does not have the private
key to decrypt the SIMPLEBLOB in the next step so it thinks the key is bad.
--
Thanks,
Ryan Menezes [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.
"Andrei" <scher...@sysoft.ru> wrote in message
news:db7201c40b29$05c90000$a301...@phx.gbl...