日期:2014-05-18  浏览次数:20713 次

怎么将abc.log文件的MD5码存为abc.md5文件
怎么将abc.log文件的MD5码存为abc.md5文件

------解决方案--------------------
C# code

    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);
        }
    }

------解决方案--------------------
C# code
using System.Security.Cryptography;