C# 2005 Md5加密后 怎么跟 asp Md5加密不一样!

2025-02-06 13:05:37
推荐回答(2个)
回答1:

是一样的

C# 取中间16位,与ASP相同

public static string Md5(string inputString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] encryptedBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(inputString));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encryptedBytes.Length; i++)
{
sb.AppendFormat("{0:x2}", encryptedBytes[i]);
}
return sb.ToString().Substring(8, 16);
}

回答2:

是因为字符的编码不一样改成一样的编码就行了,看看这吧
http://zhidao.baidu.com/question/103185401.html