Use the System.security.Cryptography.HashAlgorithm class to generate a hash code for each file, and then compare two hash codes for the same
The hashing algorithm generates a small binary "fingerprint" for a file, and from a statistical point of view, different files cannot generate the same hash code
To generate a hash code, you must first create a HashAlgorithm object, which is done by the Hashalgorithm.create method. and then call
Hashalgorithm.computehash method, which returns a byte array that stores the hash code, and then uses bitconverter.tostring () to
Replace with string for comparison.
Public Static BOOLIsvalidfilecontent (stringFilePath1,stringfilePath2) { //Create a hash algorithm objectusing(HashAlgorithm hash =hashalgorithm.create ()) { using(FileStream file1 =NewFileStream (FilePath1, FileMode.Open), file2=NewFileStream (Filepath2,filemode.open)) { byte[] hashByte1 = Hash.computehash (file1);//hash algorithm A byte array that hashes the hash code based on the textbyte[] HashByte2 =Hash.computehash (file2); stringSTR1 = bitconverter.tostring (hashByte1);//to assemble a number of bytes into a string stringSTR2 =bitconverter.tostring (HASHBYTE2); return(STR1==STR2);//Compare hash Codes } } }
"Go" "C #" to determine whether two files are the same