最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - identical md5 for JS and PHP - Stack Overflow

programmeradmin6浏览0评论

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

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

Share Improve this question asked Jun 1, 2012 at 20:11 Maarten HartmanMaarten Hartman 1,6296 gold badges26 silver badges45 bronze badges 4
  • The PHP version is correct (I checked it with MySQL). – Denys Séguret Commented Jun 1, 2012 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 Commented Jun 1, 2012 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 Commented Jun 1, 2012 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 Commented Jun 1, 2012 at 20:25
Add a ment  | 

2 Answers 2

Reset to default 5

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

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.

发布评论

评论列表(0)

  1. 暂无评论