Two files with equal contents but with different SHA256 digest
4 views (last 30 days)
Show older comments
Hello,
I read rgb 'tif' image and splitted it into r, g, b components then reconstructed it back. And to confirm that the tif image has a lossless compression scheme; i compared the two images using different tools (MSE, PSNR, and find) and the two files are 100% matching as expected.
I calculated the SHA256 digest using Hashing_Function for the two files but unfortunately the digests are not equal. And to confirm that the problem is not with the "DataHash" function that i'm using to calculate the SHA256 digest, I double-checked through the attached website SHA256_Tool which gave the exact digests as my test code.
///////////////////////////////////////////////////////////////////////
Below is the output of the test code:
MSE: 0.0; SNR: Inf; PSNR: Inf
The digital signature is not matching
/////////////////////////////////////////////////////////////////////////
I've attached the Original_Image, TestCode, and DataHash file
What is the explanation? and thanks
/////////////////////////////////////////////////////////////////////////
I was investigating the above mentioned issue and i found that when i calculate the digests for the contents of the the two images, then the digests are equal. But the digests are not equal only in the case of using the image as a file.
So i'm still looking for an exact answer about the file case and thanks again
0 Comments
Accepted Answer
Jan
on 3 Jan 2021
Edited: Jan
on 3 Jan 2021
The TIF files do not even have the same file sizes. How could you expect, that they are bit-wise identical then, which is required for an equal hash?
Although the contained data are equal, the meta data included in the file header are not. There is also an infinite number of different lossless compressions and the applied method does not necessarily create the same byte stream.
Comments of the original image:
Copyright The MathWorks, Inc.
PhotometricInterpretation: 2
PlanarConfiguration: 1
SamplesPerPixel: 3
Comments of the reconstructed image:
PhotometricInterpretation: 2
PlanarConfiguration: 1
SamplesPerPixel: 3
By the way, remember to attach the license file, if you publish a file from the file exchange. The files are published under the BSD license and removing the license information is not a fair use. To consider future changes and bugfixes, prefer to post links to the FileExchange submissions instead of copies. Thanks.
3 Comments
More Answers (1)
Walter Roberson
on 3 Jan 2021
Edited: Walter Roberson
on 3 Jan 2021
You have not taken into account that the metadata headers in the tif file can be different, including possibilities such as the same metadata contents but different internal order. Or even something a simple as a different creation date being written.
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!