Re: MacTripleDes (.NET managed and CryptoApi unmanaged interop)

From: casey chesnut (casey_at_brains-N-brawn.com)
Date: 10/15/03


Date: Tue, 14 Oct 2003 17:21:12 -0500

Yeah, I remember reading that somewhere.
In the platform.security group, a guy posted working C++ code for me that
does MacTripleDes.
I'm doing all my stuff on CE, so I ported that to eVC and ran it.
Ended up returning an 8 byte MAC with all 0's,
so I think its a bug with the CryptoApi for CE.
Using DES and RC2 as the key seemed to work fine,
but I need 3DES so that I can be compatible with the full .NET framework.
Thanks
casey

"Sebastien Pouliot" <spouliot@motus.com> wrote in message
news:uEgPR8mkDHA.2068@TK2MSFTNGP09.phx.gbl...
> Casey,
>
> It may be unrelated but in some cases the MACTripleDES implementation in
> framework version 1.0 and 1.1 don't return the same value. IIRC this
happens
> when the MACed data is a multiple of the 3DES block size (8 bytes).
>
> ----------------------------------------
> Sébastien Pouliot
> Architecte Sécurité / Security Architect
> Motus Technologies
> tel: 418 521 2100 ext 225
> fax: 418 521 2101
> courriel / email: spouliot@motus.com
>
> "casey chesnut" <casey@brains-N-brawn.com> wrote in message
> news:%23Wv6a%23FjDHA.2580@TK2MSFTNGP10.phx.gbl...
> > I need to do both keyed hashes (MacTripleDes and HmacSha1).
> > I can do HmacSha1 using pInvokes to the CryptoApi,
> > and then get the same hash value using .NET.
> >
> > But I am not having the same luck with MacTripleDes.
> > On the managed side all i do is:
> > MACTripleDES mtd = new MACTripleDES(_key);
> > byte [] mHash = mtd.ComputeHash(_value);
> >
> > For the cryptoApi, its something like this:
> > //get TripleDes key handle
> > IntPtr key = CryptGenKey(prov, Calg.TRIP_DES, GenKeyParam.EXPORTABLE);
> > //get 24 byte key as byte [] 'baKey' using nullKey export hack, and then
> > reverse it
> > IntPtr hash = CryptCreateHash(prov, Calg.MAC, key);
> > HashData(baKey, data);
> > byte [] hashVal = CryptGetHashParam(hash);
> > CryptDestroyHash(hash);
> > CryptDestroyKey(key);
> >
> > Any ideas?
> >
> > Thanks
> > casey
> >
> >
>
>