简体   繁体   English

为什么Node crypto为同一个字符串返回不同的值?

[英]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. 我希望ab都是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. 这是你在键盘上按负号时得到的。

In the second example U+2212 is used. 在第二个例子中使用U+2212

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的加密 API 返回错误的字符串? - Why does my crypto API return the wrong string? 为什么包 object-hash 和 crypto / hashlib 为 sha1 返回不同的值? - Why the packages object-hash and crypto / hashlib return different values for sha1? 为什么我的crypto.createHmac()为相同的输入生成不同的HMAC? - Why does my crypto.createHmac() generate a different HMAC for the same input? 为什么我的crypto.createHmac()为相同的输入生成不同的HMAC? - Why does my crypto.createHmac() generate a different HMAC for the same input? 为什么 Instagram API 会为同一个用户返回两个不同的 user_id 值? - Why does Instagram API return two different user_id values for the same user? Node.js API对于同一请求返回不同的值 - Node.js API return different values for the same request 为什么 jquery 返回的值与提交的值不同? - Why does jquery return different values than the values submitted? 为什么JSfiddle和Chrome控制台会返回相同功能的不同值? - Why do JSfiddle and Chrome console return different values of the same function? 为什么对同一函数的两个绑定返回不同的值 - Why two bindings to the same function return different values 为什么Whatsapp和Javascript返回不同长度的相同unicode字符串? - Why Whatsapp & Javascript return different length of same unicode string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM