We have a series of sha256 hash (one for each file in a folder) and we would like to sum them to get a global hash (the hash of the folder).
The job is to create a PHP function that will sum two hash, we will take care of the rest.
For example, the script would receive two hashs :
9F C2 B3 99 E8 33 3A 3D 48 75 BD EA 6A CC 6A F5 8B 1F 73 9A 14 86 F2 BF 17 98 35 7A 4B CE A5 C0
85 A9 E3 86 B3 5D 5D F2 AD F1 B9 EC E5 7E 56 4C 1F B6 06 05 52 94 5F 6C 94 E9 33 E4 16 0C EF A1
and return the sum :
24 6C 97 20 9C 91 97 2F F6 66 77 D7 50 4B C1 41 AB D5 79 9F 66 1A 52 2C AC 81 69 5E 62 DA 94 62
(that's the valid result by the way, you can use this example to test your script)
Be careful, these are hexadecimal characters but the value is represented each time by two digits (16*16=base 256). I added space to better understand the logic behind it.
A few tips :
1) sum is "add" operation, not "xor" operation.
3) hex dump is not sequence of hex digits. It's sequence of bytes (two digits per byte):
85A9 doesn't mean 8 5 A 9. it means 85 A9.
3) the order is reverse: "least significant" byte is first.
The final goal is to reproduce what the 7zip tool does with its CRC-SHA256 feature but in PHP...
So we would get the exact same result, we want to have a global hash of an entire folder with many files.
Generating a zip is not an option, we really want the final result to be the combined hash.
A way to test it :
- Download 7zip with the extra hash features
- pick up two files... generate the sha256 of each file and also of a folder containing both files.
- use your script to sum both individual hash.... you should get the same result at the folder hash generated by 7zip.
It has to be done with PHP... and no extra library (but you can use bcmath or other standard php modules).