C#-从自身计算md5以检查文件是否被修改 [英] C# - Calculate md5 from self to check that file is not modified

查看:377
本文介绍了C#-从自身计算md5以检查文件是否被修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查程序是否被修改(破解).

I want to check that my program is not modified (cracked).

所以我要程序从自我exe计算md5并进行比较.

So I want program to calculate md5 from self exe and compare.

if(GetMD5FromSelf() != "hash")
    Application.Exit(); //modified so exit

但是当我将哈希值放入字符串时,文件的md5将被更改.

But when I put hash to string then the md5 of file will get changed.

有什么办法吗?

推荐答案

这些是您可以使用的一些方法,

These are some ways you could do it,

选项1

您可以在线存储哈希,这可能更安全,因为如果有人要更改您的程序,他们也可以更改哈希.

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.

选项2

您可以在应用程序的末尾添加4个字节和一个字符串,并将校验和保存在那里,请注意不要在校验和中包含那些校验和,而仅验证您自己的文件大小,而不是4个字节和字符串.

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

这篇关于C#-从自身计算md5以检查文件是否被修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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