2
我遇到了将C#哈希算法与节点相匹配的问题,问题似乎是Unicode编码。有没有办法将一个字符串转换为Unicode然后散列它并将其输出为十六进制?不幸的是,我无法更改c#代码,它超出了我的控制范围。将C#MD5哈希算法与node.js匹配
节点算法
function createMd5(message) {
var crypto = require("crypto");
var md5 = crypto.createHash("md5");
return md5.update(message).digest('hex');
}
C#哈希算法
private static string GetMD5(string text)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] hashValue;
byte[] message = UE.GetBytes(text);
using (MD5 hasher = new MD5CryptoServiceProvider())
{
string hex = "";
hashValue = hasher.ComputeHash(message);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
return hex.ToLower();
}
}