表单加载时自我MD5检查 [英] Self MD5 Check When Form Load

查看:78
本文介绍了表单加载时自我MD5检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好codeproject,我有一个问题..

如何让我的Windows应用程序可以加载但是在form_load事件我的应用程序检查MD5。

如果Md5相同然后应用程序打开但是如果MD5不是sama应用程序关闭了吗?



这可能吗?但怎么样?任何建议..到目前为止我有一个片段代码来获得MD5哈希。

Hello codeproject, i have a question..
how to make my windows application can load but at the form_load event my application check MD5.
If the Md5 same then application opened but if MD5 is not sama the application closed?

are this possible? but how ? any suggestion .. so far i have a snippet code to get MD5 Hash.

推荐答案

好吧,两件事。

你可以计算任何文件的MD5例如

Well, two things.
You can compute the MD5 of any file by e.g.
using System.IO;
using System.Security.Cryptography;

namespace Bernie
{
    public class FileUtil
    {
        private static object _Lock = new object();
        public static byte[] GetMD5Hash(string Filename)
        {
            lock (_Lock)
            {
                if (File.Exists(Filename))
                {
                    using (MD5 md5 = MD5.Create())
                    {
                        using (FileStream stream = File.OpenRead(Filename))
                        {
                            return md5.ComputeHash(stream);
                        }
                    }
                }
                else
                {
                    return null;
                }
            }
        }
    }
}



但是你需要存储正确的值在某处,然后将它们与计算值进行比较。这就是安全问题(以及安全问题是您想要这样做的原因,不是吗?)可能会再次出现的问题:它们必须位于一个额外的文件中,而您无法添加MD5该文件放入文件中的该列表,因为它的MD5会改变。

当然,可以检测到病毒感染。

顺便说一句,我会做检查静态Main()已经。


But you need to store the "correct" values somewhere, and then compare them with the computed values. And that's the point where the security issues (and security issues are the reason why you want to do so, isn't it?) may come in again: they have to be located in an extra file, and you cannot add the MD5 of that file into that list in the file, as its MD5 would change.
But of course, a virus infection could be detected.
By the way, I'd do the check in static Main() already.


这篇关于表单加载时自我MD5检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆