public static bool FileMD5Validation(string md5Str, string filePath) { bool flag; if (!File.Exists(filePath)) { return(false); } using (FileStream fileStream = File.OpenRead(filePath)) { byte[] numArray = new byte[checked ((IntPtr)fileStream.Length)]; fileStream.Read(numArray, 0, (int)numArray.Length); string mD5 = EncryptUtil.ToMD5(numArray); Console.WriteLine(mD5); flag = md5Str == mD5; } return(flag); }
public static bool FileMD5Validation(string md5Str, string filePath) { if (File.Exists(filePath)) { using (var fileStream = File.OpenRead(filePath)) { byte[] fileBytes = new byte[fileStream.Length]; fileStream.Read(fileBytes, 0, fileBytes.Length); string fileMd5 = EncryptUtil.ToMD5(fileBytes); Console.WriteLine(fileMd5); return(md5Str == fileMd5); } } else { return(false); } }
public static string ToMD5(string input) { return(EncryptUtil.ToMD5(Encoding.Default.GetBytes(input))); }