unity3d的www类和java服务器进行http通信时,在验签时使用MD5加密时,如果原文含中文会和服务器上加密的不一致,碰到此种情况的朋友,希望你能得到帮助!
java服务器上编码是 utf8;
untity是c#脚本;
方法如下:
//MD5加密
private string CreateMD5Hash(string input)
{
// Use input string to calculate MD5 hash
MD5 md5 = MD5.Create();
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
// To force the hex string to lower-case letters instead of
// upper-case, use he following line instead:
// sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}