简体   繁体   English

计算并在标签中显示MD5 Hash文件

[英]calculate and display file MD5 Hash in a label

如何计算文件的MD5哈希并在标签中显示?

Yes it is possible: 对的,这是可能的:

label1.Text = GetMD5HashFromFile("somefile.txt");

where the GetMD5HashFromFile function could look like this: GetMD5HashFromFile函数可能如下所示:

public static string GetMD5HashFromFile(string filename)
{
    using (var md5 = new MD5CryptoServiceProvider())
    {
        var buffer = md5.ComputeHash(File.ReadAllBytes(filename));
        var sb = new StringBuilder();
        for (int i = 0; i < buffer.Length; i++)
        {
            sb.Append(buffer[i].ToString("x2"));
        }
        return sb.ToString();
    }
}

Yes, it's possible. 是的,这是可能的。 When you calculate the MD5 Hash of a file you just need to take the result and place it in as the text of Label control. 计算文件的MD5哈希时,只需要获取结果并将其作为Label控件的文本放入。 No problem there. 没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM