I am trying to MD5 a string in ActionScript using the MD5 algorithm that was created by Adobe and is part of AS3corelib. (http://as3corelib.googlecode.com/svn/trunk/src/com/adobe/crypto/MD5.as).
I am comparing this to an MD5 created in php that I know is correct.
If I create MD5s using AS and PHP for say a string like “abcd1234” they both are equal, as is to be expected. The problem is, when my string contains some hexadecimal in it ie “abcd\x28\xBF\x4E”, the MD5s from ActionSCript and php return different value.
Now the really strange part is as long as the hexadecimal is in the form of a number when its a string its fine and still matches:
ie
“abcd\x28\x46” will have matching values from AS’s MD5 and php’s MD5.
While
“abcd\x28\xBF” will yield different hashes.
Anyone have any ideas? I’ve tested the php MD5 thoroughly and I know it is correct and the ActionScript is incorrect. I appreciate the help, thanks for reading and I apologize if this was confusing. I’m a noob when it comes to string encoding, representation etc.
Thanks,
Drew S.
Most likely, PHP and ActionScript are using different encodings for strings; one is probably using ISO-8859-1 and the other is using UTF-8.
For
abcd\x28\xBF, the values are:fcfebaeb81afe401c4b608dc684ad08funder ISO-8859-147ef883a009ddbe01711ece0a0a8764eunder UTF-8And for
abcd\x28\xBF\x4E(your other example), the values are:ea382d63efca32d8d7861a314a6112e3under ISO-8859-1dc11cdbaa05aa41640a821fb8e290eaeunder UTF-8