3

for a small project I need identical md5 hashes for both JS and PHP. Im using this javascript to convert a word to md5 (the .min version)

the word 'hello' outputs in

JS: ec59d44dee488759467970486fc9402d

PHP: 5d41402abc4b2a76b9719d911017c592

so they are not identical. I've tried to use md5(utf8_encode($word)); instead of md5($word);

but both gave the same result.

Any ideas? Help is much appreciated

Maarten Hartman
  • 1,611
  • 6
  • 26
  • 45
  • The PHP version is correct (I checked it with MySQL). – Denys Séguret Jun 01 '12 at 20:15
  • Don't understand your question. Are you creating two files (a PHP and a JS) of are you hashing the String only? – Alfabravo Jun 01 '12 at 20:20
  • 2
    You're not using the same value in each. Paj's version and the PHP version both work correctly. So something is changing in the input value. – Jonathan M Jun 01 '12 at 20:20
  • okay guys, the mistake was mine, I made a script that on keyup converted the word to md5, somehow I've let the script convert the md5 field... thanks guys. Still all these posts helped, PaulPRO post made me look closer and made me find the problem :) – Maarten Hartman Jun 01 '12 at 20:25

2 Answers2

5

The md5 function on phpjs gives the correct results. It is dependent on utf8_encode, so you need that as well.

Paul
  • 139,544
  • 27
  • 275
  • 264
  • The important detail here is the character encoding. MD5, like all hashes, works on the binary, which differs between the different encodings. – DampeS8N Jun 01 '12 at 20:31
0

If you want to generate md5 value in Javascript, you may use this md5 package

var md5 = require('md5');
console.log(md5('message'));

Then, use this md5 online tool to verify the result.

cwtuan
  • 1,718
  • 1
  • 18
  • 20