MD5哈希在C#中不匹配的MD5哈希的动作脚本 [英] MD5 Hash in C# doesn't match MD5 Hash in Action Script

查看:133
本文介绍了MD5哈希在C#中不匹配的MD5哈希的动作脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我散列在动作脚本一些数据,然后比较哈希一个计算在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#:<​​/ P>

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.

这篇关于MD5哈希在C#中不匹配的MD5哈希的动作脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆