zoukankan      html  css  js  c++  java
  • C# get md5,renamed file and can not change file's md5

    using System;
    using System.Text;
    using System.IO;
    using System.Security.Cryptography;
    
    namespace ConsoleApplication13
    {
        class Program
        {
            static void Main(string[] args)
            {
                string imgPath1 = @"....Imageslj.jpg";
                string imgPath2 = @"....Imageslj2.jpg";
                string imgPath3 = @"....Imageslj3.jpg";
                string imgPath4 = @"....Imageslj4.jpg";
                string md51 = GetMD5(imgPath1);
                string md52 = GetMD5(imgPath2);
                string md53 = GetMD5(imgPath3);
                string md54 = GetMD5(imgPath4);
                Console.WriteLine($"path:{imgPath1},md51:{md51}");
                Console.WriteLine($"path:{imgPath2},md52:{md52}");
                Console.WriteLine($"path:{imgPath3},md53:{md53}");
                Console.WriteLine($"path:{imgPath4},md54:{md54}");
                Console.ReadLine();
            }
    
            static string GetMD5(string sourceFile)
            {
                StringBuilder md5Builder = new StringBuilder();
                if (File.Exists(sourceFile))
                {
                    using (MD5 md5Hash = MD5.Create())
                    {
                        using(FileStream fs=File.Open(sourceFile,FileMode.Open))
                        {
                            byte[] md5Bytes = md5Hash.ComputeHash(fs);
                            for (int i = 0; i < md5Bytes.Length; i++)
                            {
                                string sortedByte = md5Bytes[i].ToString("x2");
                                if (!string.IsNullOrEmpty(sortedByte))
                                {
                                    md5Builder.Append(sortedByte);
                                }
                            }
                        }                      
                    }
                }
                return md5Builder.ToString();
            }
        }
    }
  • 相关阅读:
    Pytorch笔记
    Anaconda使用
    最大流最小割算法
    pycallgraph--使用pycallgraph绘制Python函数调用关系图
    论文表格--三线表
    0514数据结构--递归、排序和查找
    0511操作系统
    0510操作系统
    ACWING算法提高课-动态规划
    删括号
  • 原文地址:https://www.cnblogs.com/Fred1987/p/12009960.html
Copyright © 2011-2022 走看看