如何使用python和unity3d C#比较图像的哈希值?

我有一个unity3d应用程序,它请求图像名称的json字符串,包括其在django网络服务器中的哈希值。然后,我的统一应用程序将检查我现有的图像哈希(如果它与请求的json相同)。我的问题是,统一的哈希结果与我的python哈希结果值不同。我还尝试对两个字符串进行哈希处理,并且它返回相同的哈希值。

Python哈希:

>>> image_file = open('C:/image.png').read()
>>> hashlib.md5(image_file).hexdigest()
'658e8dc0bf8b9a09b36994abf9242099'

Unity3d哈希:

public static string ComputeHash()
{
    // Form hash
    system.security.Cryptography.MD5 h =system.security.Cryptography.MD5.Create();
    var myImage = File.OpenRead(PathByPlatform("image.png"));
    var data = h.ComputeHash(myImage );

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    for (int i = 0; i < data.Length; ++i)
    {
        sb.Append(data[i].ToString("x2"));
    }
    return sb.ToString();

    //This fucntion returns 
    //fac7f19792a696d81be77aca7dd499d0
}
liangying142 回答:如何使用python和unity3d C#比较图像的哈希值?

您是否尝试过open('C:/image.png',"rb").read()以便以二进制模式读取文件?

读取不带“ b”的文件会将Windows上的行尾字符从CR / LF更改为LF,这会影响哈希。 (至少对于python2)

本文链接:https://www.f2er.com/3139599.html

大家都在问