narkive is for sale. Interested? (dismiss)
Discussion:
CryptDecryptMessage and CSP failed?
(too old to reply)
Krypto Karya
2014-09-20 03:08:11 UTC
Permalink
I want to use CryptDecryptMessage function and look at example shows at MSDN on CryptDecryptMessage (http://msdn.microsoft.com/en-us/library/windows/desktop/aa382376(v=vs.85).aspx)

It states,

if(DecryptMessage(
pbEncryptedBlob,
cbEncryptedBlob,
hCryptProv,
hStoreHandle))
{
printf("Decryption succeeded. \n");
}

I trace the hCryptProv and realized that there is NO call for hCryptProv in the CryptDecryptMessage function. The CryptDecryptMessage function only links to the hStoreHandle in the function call as below,

HCERTSTORE CertStoreArray[] = {hStoreHandle};

and the hStoreHandle is initialized in the CRYPT_DECRYPT_MESSAGE_PARA structure.

DecryptParams.cCertStore = 1;
DecryptParams.rghCertStore = CertStoreArray;

The problem is, with token and smart card CSP, I keep getting error 8009200C (CRYPT_E_NO_DECRYPT_CERT
No certificate was found having a private key property to use for decrypting). In my understanding, i need to link to hCryptProv to access the private key.

Question how to enable the CryptDecryptMessage function for the CSP?

Between i don't have any problem in signing operation CryptSignMessage.
SigParams.pSigningCert = pCertContext;
CryptSignMessage().

Any suggestion on how can i test the CSP with CryptDecrptMessage?
Krypto Karya
2014-11-25 16:42:22 UTC
Permalink
Done. Some one else code error. I just need to believe in Microsoft sample code :)
Loading...