I'm trying to a compute a SHA-1 checksum for an entire directory structure.
What I have done so far is to recursively compute the SHA-1 for each regular file and append all the checksums together. The problem is that this makes the computing dependent on the order of traversing the files
I.e if I have a folder containing the files
file1.dat file2.dat
and the other folder containing the same files, but ordered by
file2.dat file1.dat
this will compute different checksums.
How can I make the SHA-1 computation order independent?
Thanks!
You have at least two options with that:
Create a archive file, for directory and then create the digest for it. (zip, jar)
Read all file bytes into single byte array and then create from it the digest.
Pre-order data before you create the digest, using your algorithm.
Create a two list of digest and compare them.
Personally I would go with option one, is fast and easy.