首页 > 其他 > 详细

获取文件Md5值

时间:2016-11-04 14:13:32      阅读:243      评论:0      收藏:0      [点我收藏+]
        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;
            }
        }

 

获取文件Md5值

原文:http://www.cnblogs.com/liuph/p/6029786.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!