B
Badrinath Mohan
Hi guys
This is strange but Cryptimportkey returns with NTE_BAD_KEY
I create keys using Diffie Hellman CSP and then export it.
I import it in another function but it fails saying Bad Key.
So i decided to immediately import it after exporting to check it out..
Here also it fails with NTE_BAD_KEY
Any comments?
Thanks and waiting for ur replies
Badri
----------------------Attached --------------- -----
HCRYPTPROV hProv;
HCRYPTKEY hKey;
HCRYPTKEY hSecretKey;
BYTE *pbyKeyData;
DWORD dwKeyLen=0;
HANDLE hPublicFile;
DWORD dwBytesWritten=0;
int nError=0;
if(!CryptAcquireContext(&hProv, "TestImport",
MS_ENH_DSS_DH_PROV,PROV_DSS_DH, 0))
{
TRACE("\nError during CryptAcquireContext!");
}
if(CryptGenKey(hProv,CALG_DH_EPHEM,CRYPT_EXPORTABLE,&hKey))
{
TRACE("\nA session key has been created");
}
else
{
TRACE("\nError during CryptGenKey");
int nk=GetLastError();
exit(1);
}
BYTE *pbData=0;
DWORD dwDataLen=0;
if(!CryptExportKey(hKey,0,PUBLICKEYBLOB,0,NULL,&dwKeyLen))
TRACE("\nError during CryptExportKey");
pbyKeyData=new BYTE[dwKeyLen];
if(!CryptExportKey(hKey,0,PUBLICKEYBLOB,0,pbyKeyData,&dwKeyLen))
TRACE("\nError during CryptExportKey");
//i export it into a file ...and then do a import in another function.
It fails there so i have tested cryptimportkey in the same
function after the export and it fails here tooo...
if(!CryptImportKey(hProv,pbyKeyData,dwKeyLen,0,0,&hSecretKey))
{
TRACE("\nError during CryptImportKey!");
nError=GetLastError();
}
This is strange but Cryptimportkey returns with NTE_BAD_KEY
I create keys using Diffie Hellman CSP and then export it.
I import it in another function but it fails saying Bad Key.
So i decided to immediately import it after exporting to check it out..
Here also it fails with NTE_BAD_KEY
Any comments?
Thanks and waiting for ur replies
Badri
----------------------Attached --------------- -----
HCRYPTPROV hProv;
HCRYPTKEY hKey;
HCRYPTKEY hSecretKey;
BYTE *pbyKeyData;
DWORD dwKeyLen=0;
HANDLE hPublicFile;
DWORD dwBytesWritten=0;
int nError=0;
if(!CryptAcquireContext(&hProv, "TestImport",
MS_ENH_DSS_DH_PROV,PROV_DSS_DH, 0))
{
TRACE("\nError during CryptAcquireContext!");
}
if(CryptGenKey(hProv,CALG_DH_EPHEM,CRYPT_EXPORTABLE,&hKey))
{
TRACE("\nA session key has been created");
}
else
{
TRACE("\nError during CryptGenKey");
int nk=GetLastError();
exit(1);
}
BYTE *pbData=0;
DWORD dwDataLen=0;
if(!CryptExportKey(hKey,0,PUBLICKEYBLOB,0,NULL,&dwKeyLen))
TRACE("\nError during CryptExportKey");
pbyKeyData=new BYTE[dwKeyLen];
if(!CryptExportKey(hKey,0,PUBLICKEYBLOB,0,pbyKeyData,&dwKeyLen))
TRACE("\nError during CryptExportKey");
//i export it into a file ...and then do a import in another function.
It fails there so i have tested cryptimportkey in the same
function after the export and it fails here tooo...
if(!CryptImportKey(hProv,pbyKeyData,dwKeyLen,0,0,&hSecretKey))
{
TRACE("\nError during CryptImportKey!");
nError=GetLastError();
}