Igor Obradović
Igor Obradović

Reputation: 3

Sha256, sha512 for multiple files

What would be the best way to combine checksum of the multiple files (or even folders?) ?

For multiple files I tried to do the approach:

  1. calculate one checksum
  2. calculate other checksum
  3. combine them into one byte array
  4. calculate checksum of combined

As one of the existing answers proposed, but I can't get correct result, the way I was checking whether checksum is correct is with 7zip. There is always possibility that there is bug there, but highly unlikely.

I don't need the strict code example of how to do it, but rather an rough overview of what to do.

Thanks in advance guys!

Upvotes: 0

Views: 1851

Answers (1)

Ian Boyd
Ian Boyd

Reputation: 256761

It really is your choice, and what goals you like:

  • Keep a single SHA2 object, and keep adding files to it

Another suggestion is:

  • hash each file separately
  • keep all the individual hashes - so people can validate each file independently
  • hash the array of hashes, to make sure the collection of hashes is undamaged

By keeping the hash of each file, someone can validate each file independently (i.e. they don't need access to all the data to verify the file's contents)

The approach used by BitTorrent is to:

  • treat all files as long blob of data
  • hash each 128 MB chunk (so that you don't have thousands of small hashes for thousands of small 1k files)
  • and then hash array of hashes, to make sure the collection of hashes is undamaged

Upvotes: 1

Related Questions