I want to check that my program is not modified (cracked).
So I want program to calculate md5 from self exe and compare.
if(GetMD5FromSelf() != "hash")
Application.Exit(); //modified so exit
These are some ways you could do it,
You could store the hash online, This is probably safer because if someone is going to change your program they can also change the hash.
You could add 4 bytes and a string to the end of your application and save the checksum there, Beware to not include those in your checksum and only validate your own file size, not the 4 bytes and the string.
List<byte> total = new List<byte>(File.ReadAllBytes(System.Reflection.Assembly.GetEntryAssembly().Location)); byte totalByteArray = total.ToArray(); int OwnSize = 115200;//Size of you exe file without checksum int Md5Length = BitConverter.ToInt32(totalByteArray, OwnSize+4); string NormalFileNameString = Encoding.ASCII.GetString(totalByteArray, OwnSize, Md5Length);