md5 result from CMD5 different from PHP md5 result

Login to reply to this topic.
Tue, 2008-09-02 16:47
Joined: 2008-09-02
Forum posts: 4

Hi,

I'm trying to use the CMD5 class (in hash.h), to get the md5 hash of a string and pass it to a web page, however when I do the result is always different to what is returned from the md5 function in php.

The code I'm using is

TBuf<KDefaultBufferSize> userName;
TBuf<KDefaultBufferSize> password;
CAknMultiLineDataQueryDialog* dlg =
        CAknMultiLineDataQueryDialog::NewL(userName, password);

if (!dlg->ExecuteLD(R_DIALOG_USER_PASSWORD_QUERY))
        break;

                       
TPtrC8 ptr((TUint8*)password.Ptr(), password.Size());
                       
CMD5* hasher = CMD5::NewL();
CleanupStack::PushL(hasher);
TPtrC8 hashedSig(hasher->Hash(ptr));
                                       
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
TPtr8 bufPtr = buf->Des();

//get the hex value
for(TInt i=0; i < hashedSig.Length(); i++)
{
        bufPtr.AppendFormat(_L8("%+02x"),hashedSig[i]);
}
CleanupStack::PopAndDestroy(hasher);
CleanupStack::PushL(buf);

// Insert the username and password after the uri
TBuf8<KDefaultBufferSize> uri8;
uri8.Append(KMTAddContactURI);
uri8.Append(KMTUsernameURI);
uri8.Append(userName);
uri8.Append(KMTPasswordURI);
uri8.Append(bufPtr);

The result from PHP for "a" would be 0cc175b9c0f1b6a831c399e269772661. But from the above code the result for "a" is 4144e195f46de78a3623da7364d04f11

Can anyone help me out with getting this to work?


Tue, 2008-09-02 21:22
Joined: 2003-12-05
Forum posts: 672
Re: md5 result from CMD5 different from PHP md5 result

TBuf is unicode; 16 bit chars -- is it the same when doing php "stuff"?

Tue, 2008-09-02 22:33
Joined: 2008-09-02
Forum posts: 4
Re: md5 result from CMD5 different from PHP md5 result

Thanks I did a search on that and it looks like you are right.

4144e195f46de78a3623da7364d04f11 is the md5 hash of the Unicode encoding of "a", while 0cc175b9c0f1b6a831c399e269772661 is the md5 hash of the ascii encoding.

Is there a way to convert the unicode to ascii on Symbian? As I can't change the web application I need to connect to.

Wed, 2008-09-03 06:04
Joined: 2008-01-16
Forum posts: 165
Re: md5 result from CMD5 different from PHP md5 result

Hi matrim,

you can checkout these link to convert Unicode to UTF8
http://www.newlc.com/topic-4891
http://discussion.forum.nokia.com/forum/showthread.php?t=28110
also checkout CnvUtfConverter class in sdk.
hopefully this will help you. Smiling


Thanks & Regards,
Md.Khalid Ahmad

Wed, 2008-09-03 10:10
Joined: 2008-09-02
Forum posts: 4
Re: md5 result from CMD5 different from PHP md5 result

Thanks, declaring a TBuf8 and using the copy function on the TBuf before the hash seems to do it.

  • Login to reply to this topic.