获取文件Md5值

        private static string GetFileMD5(string filePath)
        {
            string _md5Value = string.Empty;
            try
            {
                if (System.IO.File.Exists(filePath))
                {
                    FileStream file = new FileStream(filePath, FileMode.Open);
                    System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                    byte[] retVal = md5.ComputeHash(file);
                    file.Close();
                    file.Dispose();
                    _md5Value= BitConverter.ToString(retVal).Replace("-", "");
                }
                return _md5Value;
            }
            catch (Exception ex)
            {
                //throw new Exception(string.Format("GetFileMD5_Error_{0}_{1}", DateTime.Now, ex.Message));
                return _md5Value;
            }
        }
原文地址:https://www.cnblogs.com/liuph/p/6029786.html