.NET CryptoAPITransform and KeyHandle interop

From: Michel Gallant (neutron_at_NOSPAMistar.ca)
Date: 12/18/03


Date: Thu, 18 Dec 2003 09:51:19 -0500

I understand that CryptoAPITransform.KeyHandle returns a
handle to the native symmetric key handle (for underlying capi
CSP like RC2, TripleDES etc..)

There is no problem acquiring such a keyhandle in managed code:

  CryptoAPITransform capitrans = (CryptoAPITransform) encryptor ;
  IntPtr hsymkey = capitrans.KeyHandle ; //native key handle

but this keyhandle fails when supplied to CryptoAPI functions via Pinvoke
(typically with Bad Key error).
Anyone with experience here?

Is the underlying SymmetricAlgorithm keyhandle marked as "Exportable" in
capi? SymmetricAlgorithm classes don't seem to have properties that allow
controlling some dwFlags that CryptoGenKey() does.

Thanks,
 - Mitch Gallant
   MVP Security