[TIP] Visual C++ CAPICOM MD5
From: K D (samudbhava_at_gmail.com)
Date: 10/26/04
- Previous message: Jack: "Custom CSP - How to use for certificate rollout ? (malfunction)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 26 Oct 2004 03:03:01 -0700
I searched google groups (and google as well) for 'IHashedDataPtr' ...
finding nothing, I thought it was safe to go ahead and post this code.
It shows the wrong and right way of generating md5 hash. It took me a
while to figure this out and I hope it will save time for you.
#import "capicom.dll" no_namespace
:
:
void CEssImpl::HashTest()
{
// from: http://pajhome.org.uk/crypt/md5/
// hello! => 5a8dd3ad0756a93ded72b823b19dd877
IHashedDataPtr iHashedData(__uuidof(HashedData));
iHashedData->Algorithm=CAPICOM_HASH_ALGORITHM_MD5;
// data to hash
CString data("hello!");
// wrong way! gives => B38A88C2EEC50E7C31FF95A5BFDB9EF6
_bstr_t t1=(_bstr_t)data;
iHashedData->Hash(t1);
cout << iHashedData->Value << endl;
// right way! gives => 5A8DD3AD0756A93DED72B823B19DD877
_bstr_t t2;
t2.Assign(SysAllocStringByteLen(data, data.GetLength()));
iHashedData->Hash(t2);
cout << iHashedData->Value;
}
- Previous message: Jack: "Custom CSP - How to use for certificate rollout ? (malfunction)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]