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

  • 相关阅读:
    【京东面试复盘】一面二面真题面经解析
    4个小技巧带你轻松入门kafka!
    python 函数
    python 文件修改
    python 文件基本操作
    python 集合的一些用法
    python 字典的应用_简单的三级列表
    python 字典的一些用法
    python 字符串的一些用法
    python 列表应用-简单的购物车
  • 原文地址:https://www.cnblogs.com/CielWater/p/3757245.html
Copyright © 2011-2022 走看看