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();
            }

  • 相关阅读:
    使用respondsToSelector:来发现对象是否响应消息
    使用iskindofclass来发现对象是否是某类或其子类的实例
    集合set的使用
    字典的使用
    数组的使用
    对NSNumber的理解
    数组、字典和集合的定义
    强引用strong和弱引用weak的定义
    类工厂方法的定义
    POJ 2262 / UVa 543
  • 原文地址:https://www.cnblogs.com/CielWater/p/3757245.html
Copyright © 2011-2022 走看看