如何在PHP和Node.js中使用哈希具有相同的值?

mur*_*lai 2 php hash md5 signature node.js

在node.js中,我有:

var h = crypto.createHash("md5");   // md5
h.update("AAA");
h.digest("hex");
Run Code Online (Sandbox Code Playgroud)

在PHP我有:

md5("AAA");
Run Code Online (Sandbox Code Playgroud)

但是,两者都有不同的价值.我怎么能这样做?或者,我应该使用什么其他算法使它们相同,以便我可以将它用作签名计算.谢谢.


碰到..实际上.我的错.当我测试它时,有一个bug ..它将md5相同的东西.

Alf*_*red 10

我过去做的简单的谷歌搜索给了我=> http://japhr.blogspot.com/2010/06/md5-in-nodejs-and-fabjs.html

Node.js的

脚本:

var crypto = require('crypto');
var hash = crypto.createHash('md5').update('AAA').digest("hex");
console.log(hash);
Run Code Online (Sandbox Code Playgroud)

输出:

alfred@alfred-laptop:~/node/hash$ node hash.js 
e1faffb3e614e6c2fba74296962386b7
Run Code Online (Sandbox Code Playgroud)

PHP

<?php
echo md5("AAA");
Run Code Online (Sandbox Code Playgroud)

输出:

alfred@alfred-laptop:~/node/hash$ php md5.php 
e1faffb3e614e6c2fba74296962386b7
Run Code Online (Sandbox Code Playgroud)

PHP和node.js的输出是相等的.

C扩展名

您也可以查看使用C实现的https://github.com/brainfucker/hashlib,它会更快.