代码如下:
1 static MD5 s_md5; 2 static MD5 MD5Obj 3 { 4 get { return s_md5 ?? (s_md5 = MD5.Create()); } 5 } 6 7 public static string ComputeHash(byte[] buffer) 8 { 9 if (buffer == null || buffer.Length < 1) 10 return ""; 11 12 byte[] hash = MD5Obj.ComputeHash(buffer); 13 StringBuilder sb = new StringBuilder(); 14 15 foreach (var b in hash) 16 sb.Append(b.ToString("x2")); 17 18 return sb.ToString(); 19 }