zoukankan      html  css  js  c++  java
  • c# 计算字符串和文件的MD5值的方法

    快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中。
     
    HTML开发Mac OS App 视频教程》
     
    官方QQ群:(申请加入,说是我推荐的
    • App实践出真知 434558944       App实践出真知
    • App学习交流 452180823          App实践出真知
     
    Step1:引入库
    1 using System.Security.Cryptography;
    2 using System.IO;

     

    Step2: 计算字符串的Md5值    

     1         static public string GetMD5WithString(string sDataIn)
     2         {
     3             string str = "";
     4             byte[] data = Encoding.GetEncoding("utf-8").GetBytes(str);
     5             MD5 md5 = new MD5CryptoServiceProvider();
     6             byte[] bytes = md5.ComputeHash(data);
     7             for (int i = 0; i < bytes.Length; i++)
     8             {
     9                 str += bytes[i].ToString("x2");
    10             }
    11             return str;
    12         }

     

    Step3:计算文件的Md5值

     

    1         static public string GetMD5WithFilePath(string filePath)
    2         {
    3             FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    4             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    5             byte[] hash_byte = md5.ComputeHash(file);
    6             string str = System.BitConverter.ToString(hash_byte);
    7             str = str.Replace("-", "");
    8             return str;
    9         }

     

     

  • 相关阅读:
    换零钞
    空心菱形
    生成回文数
    机器人数目
    胡同门牌号
    七星填数
    阶乘位数
    打印数字
    平方末尾
    数位和
  • 原文地址:https://www.cnblogs.com/RTdo/p/4483767.html
Copyright © 2011-2022 走看看