zoukankan      html  css  js  c++  java
  • 获取文件hash值

     public string getFilesMD5Hash(string file)
            {
                //MD5 hash provider for computing the hash of the file
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

                //open the file
                FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, 8192);

                //calculate the files hash
                md5.ComputeHash(stream);

                //close our stream
                stream.Close();

                //byte array of files hash
                byte[] hash = md5.Hash;

                //string builder to hold the results
                StringBuilder sb = new StringBuilder();

                //loop through each byte in the byte array
                foreach (byte b in hash)
                {
                    //format each byte into the proper value and append
                    //current value to return value
                    sb.Append(string.Format("{0:X2}", b));
                }

                //return the MD5 hash of the file
                return sb.ToString();
            }

  • 相关阅读:
    CodeSmith入门教程
    AJAX调用实例
    药品监控增加表结构
    典型SQL 语句总结
    CRM中常用代码
    win2000sever+IIS5不能下载exe文件处理方法
    常用的文件对应的MIME类型
    数据库范式1NF 2NF 3NF BCNF
    多线程编程中如何更改UI值
    NHibernate学习笔记(2)—关系映射
  • 原文地址:https://www.cnblogs.com/CielWater/p/3757245.html
Copyright © 2011-2022 走看看