Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
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.
Posted

1 solution

Well, two things.
You can compute the MD5 of any file by e.g.
C#
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;
                }
            }
        }
    }
}

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.
 
Share this answer
 
Comments
Gun Gun Febrianza 5-Jun-13 17:59pm    
thank you so much sir.. after iam going iwill try it soon :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900