C# get md5,renamed file and can not change file's md5
程序员文章站
2022-08-08 13:42:54
using System; using System.Text; using System.IO; using System.Security.Cryptography; namespace ConsoleApplication13 { class Program { static void Mai... ......
using system; using system.text; using system.io; using system.security.cryptography; namespace consoleapplication13 { class program { static void main(string[] args) { string imgpath1 = @"..\..\images\lj.jpg"; string imgpath2 = @"..\..\images\lj2.jpg"; string imgpath3 = @"..\..\images\lj3.jpg"; string imgpath4 = @"..\..\images\lj4.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(); } } }
上一篇: 一人经济兴起 其中蕴含着哪些创业方式
下一篇: 新手宝妈看过来,2岁宝宝吃什么才营养