I am trying to detect when a Word or PDF document is different from the version that is loaded, I have a form in which a document is loaded through an OpenDialog which can be replaced. I do not have a method to detect if the new version that the user loads actually contains changes. If the user wants to replace the document, it is necessary to change the name so that it is replaced in another way. If the document that he wants to replace has the same name as the new one, he did not replace it.
Could you do it through a checksum or some hash of the documents and compare them?
You can do it using the date of creation and last modification as follows:
Using the date is an easy way to tell if the file has been modified.
To know if a file has been altered or if it maintains its authenticity, there is a security technique called
checksum
(checksum) which uses specific algorithms to check the integrity of the file and be certain that it has not been tampered with and is totally reliable.checksum
is an algorithm, called , that is executed onhash criptográfico
a file, which will return a value, this value will be used to check with the values obtained from the verification of the source file and the current one. If they match, we can be sure that the file is the same without modifications.Checksum uses various algorithms to check the integrity of a file, the most common are:
It is an algorithm
criptográfico de 128 bits
and is one of the most used today. (unsure)It
conjunto de funciones hash
is and is widely used in electronic signature applications since it generates hash codes between 160 and 254 bits.It is one of the most used algorithms in various protocols due to its scope at the security level, such as
TLS, SSL, PGP, SSH
, among others. SHA-256 always has64 caracteres
independent of the size of the length of the file where each digit is a letter from A to F and each one represents 4 bits of information for which 64 characters x 4 bits = 256 bits which increases its level of protection.This speed behavior is obtained on computers that use CPUs with x64 architecture and 64-bit operating systems.
MSDN SHA-512 algorithm information and usage example
Information about benchmarks and tests about both algorithms.
Is SHA-256 vs SHA-512 algorithm faster?