Decrypting Enveloped data messages with .NET and P/Invoke

From: Michel Gallant (neutron_at_istar.ca)
Date: 09/05/03


Date: Fri, 5 Sep 2003 17:34:53 -0400


Currently, .NET framework does not directly support CMS/pks7
encrypted message encapsulations, although I hear great things
are coming in Whidbey!
While CAPICOM 2 provides the EnvelopedData object, there are
some known .NET <-->COM interop marshaling issues involving
bstr-->managed strings and binary data truncation.
The current workaround is to disassemble/modify/reassemble the COM
interop assembly ... slightly messy.

As always, it is possible to Pinvoke to CryptoAPI to get the needed
functionality :-)
Here is a sample utility, showing how to invoke the CryptoAPI simplified
message function CryptDecryptMessage() to decode/decrypt most
standard CMS/pkcs7 enveloped messages:
    http://pages.istar.ca/~neutron/feature/decenvelop.html (current feature article).

 - Michel Gallant
   MVP Security
   http://pages.istar.ca/~neutron


Loading