using System; using System.Collections.Generic; using System.Text; using System.IO; namespace CommonLang { public static class CMD5 { public static string CalculateMD5(Stream stream) { System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create(); md5Hasher.ComputeHash(stream); return CUtils.ToHexString(md5Hasher.Hash); } public static string CalculateMD5(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { return CalculateMD5(ms); } } public static string CalculateMD5(string text, Encoding encoding) { using (MemoryStream ms = new MemoryStream(encoding.GetBytes(text))) { return CalculateMD5(ms); } } public static string CalculateMD5(FileInfo file) { using (FileStream ms = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { return CalculateMD5(ms); } } } }