[英]Why does Node crypto return different values for the same string?
I am trying to run this program: 我正在尝试运行此程序:
var crypto = require('crypto');
var a = crypto.createHash('md5').update('89Zr-J591').digest('hex');
var name = '89Zr−J591';
var b = crypto.createHash('md5').update(name).digest('hex');
console.log(a); //c6281bc77bea86a92df59225357b6b54
console.log(b); //a3853813486b53eca6bf7d2428876161
console.log(a === b); //false
I expect both a
and b
to be true
... to be the same. 我希望a
和b
都是true
......是一样的。
Why is this not the case? 为什么不是这样? Why are they different? 他们为什么不同?
They are not the same string, see the hyphen: 它们不是同一个字符串,请参见连字符:
'89Zr-J591'
// ^ this is U+002D
'89Zr−J591'
// ^ this is U+2212
% charinfo −-
U+2212 MINUS SIGN [Sm]
U+002D HYPHEN-MINUS [Pd]
In the first example U+002D
is used. 在第一个例子中,使用U+002D
。 Which is what you get when pressing minus on your keyboard. 这是你在键盘上按负号时得到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.