R
R
Rag'n' Code Man2019-11-23 16:02:18
Encryption
Rag'n' Code Man, 2019-11-23 16:02:18

How to calculate the hash sum of a file using C#?

Hello, I started learning c# a month ago and also having fun with Unity.
I'm making a clicker in which you need to earn more coins than your friends.
My friend super mega cool proger is always hacking my game, and at one time I try to protect it from this.
In short, I want to save the last hash of the file before exiting the game, and if it was changed when the game was opened, then the game will automatically close.
I have been learning C# recently, and I am not friendly with encryption algorithms either.
Can someone write working code and explain how it works?
I've already seen working code on cyberforum, but I still don't understand how it works, what all these functions do (MD5CriptoServicePeovider, etc.)
If anyone has time to help me out with this, I'd love to hear it!
PS I'll write down your nickname in the creators section, point "special thanks" :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2019-11-23
@iDmitriyWinX

1. You can come up with any hash formula. The idea is simple - to fix the state of the file. This can be achieved using various standard hash functions (available in official examples), checksums (also available in official examples). You can count the length of the file, the number of 1s in the file, store the first 1000 bytes of the file. In general, formulas can be anything.
2. Then you need to store the hash. Your friend cracks the hash and you hash the hash. Then your friend breaks the hash of the hash, etc.
3. Therefore, if you want to protect yourself from durg, store the hash on the server, and before each launch, download it and check the file.
4. But your friend will set up a proxy and change the server traffic. Therefore, you need to somehow make sure that the hash is obtained from a reliable source. You buy a certificate and encrypt the connection to the server.
5. Well, then your friend will already start reverse engineering (disassembler). And then you can't defend yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question