[我正在尝试使用加密从NodeJS中的一个数字中获取MD5具有的值,但是我得到了一个不同的哈希值,然后从可以计算该值的站点获得了它。
[根据http://onlinemd5.com/,MD5对于1092000为AF118C8D2A0D27A1D49582FDF6339B7C。
[当我尝试在NodeJS中计算该数字的哈希值时,它给了我不同的结果(ac4d61a5b76c96b00235a124dfd1bfd1)。我的代码:
const crypto = require('crypto');
const num = 1092000;
const hash = crypto.createHash('md5').update(toString(num)).digest('hex');
console.log(hash);
我不知道这个奇怪的toString
全局var是什么,但是如果将其正常转换为字符串,它将起作用:
const hash = crypto.createHash('md5').update(String(num)).digest('hex'); // or num.toString()
查看区别:
toString(num) = [object Undefined]
(1092000).toString() = "1092000"