Log in

View Full Version : MD5 hash calculator


ChemicalX
September 12th, 2004, 16:56
Im just starting Crypto Keygenning in Visual C++ and am having a hard time trying to make a simple program to calculate a MD5 hash from a name.

Ive seen many programs from Crypto Keygen websites that do this but they all dont include sources.

If possible can anyone direct me to a sample application with source or show me how its done.



Thanks

cr.ap
September 12th, 2004, 19:43
http://www.faqs.org/rfcs/rfc1321.html

or use any of the crypto libraries which come with source Crypto++, libtomcrypt etc.

evlncrn8
September 12th, 2004, 19:44
search button
google too, read the fking faq

http://www.google.com/search?q=md5.asm&sourceid=firefox&start=0&start=0&ie=utf-8&oe=utf-8

how hard was that?

bilbo
September 13th, 2004, 01:48
Quote:
[Originally Posted by evlncrn8]md5.asm

well, since he asked for MS C++ project, he could have googled for
md5.cpp
1320 results...

If he doesn't like googling, he can try this
ftp://ftp.zedz.net/pub/crypto/hashes/mds/md5/

Regards, bilbo

neviens
September 13th, 2004, 08:07
I did it in the following way:


;--------------------------------------------------
;MD5 hash stuff from advapi32
;--------------------------------------------------
invoke CryptAcquireContext, ADDR phProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ;setup..
test eax, eax
jz _err

invoke CryptCreateHash, phProv, CALG_MD5, 0, 0, ADDR phHash ;..to MD5
test eax, eax
jz _err

invoke CryptHashData, phHash, ADDR buf1, buf1Len, 0 ;do MD5, it's possible to add more data..
test eax, eax ;..with following CryptHashData APIs
jz _err

mov buf1Len, 10h
invoke CryptGetHashParam, phHash, HP_HASHVAL, ADDR buf1, ADDR buf1Len, 0 ;get result
test eax, eax
jz _err

invoke CryptDestroyHash, phHash ;destroy..
test eax, eax
jz _err

invoke CryptReleaseContext, phProv, 0 ;..and release
test eax, eax
jz _err

Not a c++ though.
Neviens.

ChemicalX
September 13th, 2004, 14:56
FYI ive searched google and found the md5.h/md5.cpp before. Its after that my problem comes.

I do the following code:
MD5_Init(&MD5);
MD5_Update(&MD5, (unsigned char*)Name, strlen(Name));
MD5_Final((unsigned char*)MD5_bytes, &MD5);

That i presume leaves the MD5 hash at MD5_Bytes.
The problem comes when i try to print that.

I found this code in one crypto keygen

for(int i=0; i<16; i++)
{
sprintf(Temp, "%.2X", MD5_bytes[I]&0xFF);
strcat(Buffer, Temp);
}

Then I put
SetDlgItemText(hWnd, IDC_SERIAL, Buffer);

But the text in IDC_SERIAL is not the MD5 hash

Silver
September 13th, 2004, 15:00
Oh, go on then, because I feel for a fellow C/C++ coder. Leave those asm lunatics to their padded cells

Code:
#include <Wincrypt.h>

HCRYPTPROV hCrypt = NULL;
if(!CryptAcquireContext(&hCrypt, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
//failed
}


HCRYPTHASH hHash;
if(!CryptCreateHash(hCrypt, CALG_MD5, 0, 0, hHash))
{
//failed
}

char* szHashMe = "Hash this string";
if(!CryptHashData(hHash, szHashMe, strlen(szHashMe), 0))
{
//failed
}

char* szHashResult = new char[255];
if(!CryptGetHashParam(hHash, HP_HASHVAL, szHashResult, 255, 0))
{
//failed
}

CryptDestroyHash(hHash);
CryptReleaseContext(hCrypt, 0);


Erm, bear in mind I did this in about 5 mins translating neviens code...

bilbo
September 14th, 2004, 01:46
Oops, Silver, don't be too sure, you made two errors...

(1) last argument of CryptCreateHash() must be &hHash, not hHash
(2) CryptGetHashParam must not be passed 255, but the address of a long containing 255


ChemicalX, your Buffer doesn't contains ASCII characters, so you need to convert it to a printable form, before passing it to SetDlgItemText().

Please ignore the text above: that's an error of mine...neviens guess is a good one!

Regards, bilbo

neviens
September 14th, 2004, 08:12
As far as I understand, this code:

for(int i=0; i<16; i++)
{
sprintf(Temp, "%.2X", MD5_bytes[I]&0xFF);
strcat(Buffer, Temp);
}

converts the hex MD5 value to printable ASCII form.
Have you cleared a Buffer before 1st strcat?
Neviens.

Silver
September 14th, 2004, 11:44
Damn bugs. They're everywhere, and usually in my code.

ChemicalX
September 14th, 2004, 14:42
here is an example of what im tring to achieve
http://cryptokg.cjb.net/ And in the tools section download the Md5 Checker.

Now ive also downloaded C-Ripper's solution for TMG trial #4. In the keygen, C-Ripper makes a md5 hash and does some other stuff with miracl.h. So i took out all the extra parts with the miracl and made the program display just the md5 hash without any calculations (except for the converting to ascii). But when i compare it with a real hash it is not the same

I don't know if its the way to display, or maybe if the md5.h is modified
Take a look for yourself

ChemicalX
September 14th, 2004, 15:54
Sorry all this time its been my fault, i have been using the wrong include. I should have used the md5c.c from RSA but instead ive been using md5.c from some random website.
Now my program is working fine.

Thanks for your help