Which is the easiest way to validate a file and to prevend changing it’s content?
It is like to get md5 hash of file and compare saved md5 hash with current md5 hash.
How to do it in C++?
Example :
I have a file :
myfile.txt
I am content
basically what I want :
bool validate()
{
string saved_content = "I am content";
if(saved_content !== CONTENT_FROM_FILE("myfile.txt")) return false;
return true;
}
The easiest way is using a useful library OpenSSL. It has some function to calculate the hash (md5,sha1,…)
You should store hash value in memory or in secured file and periodically recalculate the hash of file. Cryptographic hash functions are more reliably than CRC32