Click to See Complete Forum and Search --> : problem with CryptImportKey()


hahaha
August 1st, 2005, 04:34 AM
Im having problem in importing the publickey from one container to another..the code is like

// get handle to the container
if (!CryptAcquireContext(&hCryptProv1,
NULL, // or set this to: "Container"
NULL, //MS_ENHANCED_PROV,
PROV_RSA_FULL,
0))
{
// MessageBox("Error during CryptAcquireContext!");
if (GetLastError() == NTE_BAD_KEYSET)
{
if (!CryptAcquireContext(&hCryptProv1,
NULL, // or set this to: "Container"
NULL, //MS_ENHANCED_PROV,
PROV_RSA_FULL,
CRYPT_NEWKEYSET))
{
MessageBox("Error during CryptAcquireContext!");
}
}
}


//then read pbkeyBlob from a file and import it to the new container
if(CryptImportKey(
hCryptProv1,
pbKeyBlob,
dwBlobLen,
0,
0,
&hPubKey))
{
MessageBox("The key has been imported.\n");
}
else
{
MessageBox("Public key import failed.");
ReportLastError();
}

but the import key fails...y is that so...any clue??