我散列在动作脚本一些数据,然后比较哈希一个计算在C#中,但它们不匹配。
I'm hashing some data in Action Script then comparing the hash to one computed in C#, but they don't match.
谁知道为什么?
下面是我做的动作脚本:
Here's what I do in Action script:
var hash : String = MD5.hash(theString);
和这里就是我做在C#:
And here's what I do in C#:
var md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(theSameString));
var sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
var hash = sBuidler.ToString();
我想这是一个编码的东西,但不能把我的手指上......让我知道!
I'm thinking it's an encoding thing, but can't put my finger on it... let me know!
-ev
动作必须使用不同的字符串编码,但我不清楚这(我试图谷歌,但它很难找到)。
ActionScript must be using a different string encoding, but it is unclear to me which (I tried to google but it’s very hard to find).
所以,我建议你尝试以下方法:
Therefore, I recommend you try the following:
Console.WriteLine(ToHex(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("ä"))));
Console.WriteLine(ToHex(MD5.Create().ComputeHash(Encoding.Unicode.GetBytes("ä"))));
Console.WriteLine(ToHex(MD5.Create().ComputeHash(Encoding.GetEncoding("ISO-8859-1").GetBytes("ä"))));
(当然, ToHex
的是,你已经写了把东西放到转换为十六进制的功能:)
(Of course, ToHex
is the function that you already wrote to turn things into into hexadecimal:)
static string ToHex(byte[] data)
{
var sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
sBuilder.Append(data[i].ToString("x2"));
return sBuilder.ToString();
}
和再检查,看看你拿到3哈希值是一样的对视了一眼在ActionScript。然后,你就会知道它编码的ActionScript使用。
And then check to see which of the three hashes you get is the same as the one in ActionScript. Then you’ll know which encoding ActionScript uses.