X3

RedSky

导航

C#获取文件MD5

public static string GetFileMD5(string filePath)
{
    using (FileStream fs = new FileStream(filePath, FileMode.Open))
    {
      System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
      byte[] bytes = md5.ComputeHash(fs);

      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < bytes.Length; i++)
      {
          sb.Append(bytes[i].ToString("x2"));
      }
    return sb.ToString();
}

 

posted on 2021-03-02 09:25  HotSky  阅读(302)  评论(0编辑  收藏  举报