c#之如何计算哈希值字符串
代码如下:
/// <summary> /// 计算哈希值字符串 /// </summary> public static string ComputeHash(byte[] buffer) { if (buffer == null || buffer.Length < 1) return ""; MD5 md5 = MD5.Create(); byte[] hash = md5.ComputeHash(buffer); StringBuilder sb = new StringBuilder(); foreach (var b in hash) sb.Append(b.ToString("x2")); return sb.ToString(); }