日期:2014-05-18 浏览次数:20713 次
private void button1_Click(object sender, EventArgs e) { CreateMD5file("c:\\temp\\abc.log"); } void CreateMD5file(string sourceFilename) { MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider(); string outputFilename = Path.ChangeExtension(sourceFilename, ".MD5"); using( FileStream input = new FileStream(sourceFilename, FileMode.Open, FileAccess.Read)) using( StreamWriter output = new StreamWriter(outputFilename, false, Encoding.ASCII)) { byte[] hash = provider.ComputeHash(input); foreach(byte b in hash) { output.Write(b.ToString("x2")); } output.Write(" *" + Path.GetFileName(sourceFilename) + System.Environment.NewLine); } }
------解决方案--------------------
using System.Security.Cryptography;