zoukankan      html  css  js  c++  java
  • C#基础-MD5验证

    一、前言

           MD5验证主要用于更新文件功能方面,服务器告知客户端要下载哪些更新文件并提供给客户端其MD5值,客户端从服务器将更新文件下载到本地并计算下载文件的MD5值,将本地接收的MD5值与服务器提供的MD5值进行比对,如果相同则说明下载的文件与服务器提供的文件是一致的,如果不相同则说明下载后文件可能有缺失,应丢弃或断点续传。

    二、计算文件的MD5值

    using System.Security.Cryptography;
    using System.Text;
    
    using(FileStream file = new FileStream(FilePath, System.IO.FileMode.Open))
    {
           MD5 md5 = new MD5CryptoServiceProvider();
           byte[] YourFile = md5.ComputeHash(file);
           file.Close();
           StringBuilder FileMD5 = new StringBuilder();
           for (int i = 0; i < YourFile.Length; i++)
           {
              FileMD5.Append(YourFile[i].ToString("x2"));
           }
           FileMD5.ToString();
    }
  • 相关阅读:
    数组_leetcode283
    数组_leetcode438
    数组_leetcode215
    数组_leetcode167
    数组_leetcode209
    数组_leetcode88
    数组_leetcode80
    数组_leetcode76
    数组_leetcode75
    数组_leetcode27
  • 原文地址:https://www.cnblogs.com/lovecsharp094/p/5866484.html
Copyright © 2011-2022 走看看