R
ralvaradot
Hi for All!
How can i do encryp a string with MD5?
Thanks in advance!
RA
How can i do encryp a string with MD5?
Thanks in advance!
RA
Don Dumitru said:Can you give us the details of what you are trying to accomplish? MD5 is
not actually an encryption algorithm, but is instead a hashing algorithm.
So I am guessing that you want to use this as part of communicating with
some other piece of software, that wants an MD5 hash of some data?
That said, you could use the Crypto API (CAPI) to accomplish this. The
basic steps are...
HCRYPTPROV prov;
HCRYPTHASH hash;
BOOL bSuccess;
BYTE rgbResult[16];
DWORD cbResult = sizeof(rgbResult);
bSuccess = CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
bSuccess = CryptCreateHash(prov, CALG_MD5, NULL, 0, &hash);
bSuccess = CryptHashData(hash, pbData, dwDataLen, 0); // pass the
data to be hashed to this call
bSuccess = CryptGetHashParam(hash, HP_HASHVAL, rgbResult, &cbResult,
0);
// rgbResult has the resulting hash value
CryptDestroyHash(hash);
CryptDestroyContext(prov);
This is not intended to be shipping code. It is just intended to give you
the functions you will call, along with the appropriate parameters, to do
MD5. Some bad things about the code above are: Doesn't actually check
the error returns from the functions. Has a hardcoded length of 16 bytes
for the output of the MD5 hash. Hasn't been run through a compiler, so
there might be typo's and such.
--Don
ralvaradot said:Hi for All!
How can i do encryp a string with MD5?
Thanks in advance!
RA