Two files with equal contents but with different SHA256 digest

조회 수: 1 (최근 30일)
RMT
RMT 2021년 1월 3일
댓글: RMT 2021년 1월 3일
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

채택된 답변

Jan
Jan 2021년 1월 3일
편집: Jan 2021년 1월 3일
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
RMT
RMT 2021년 1월 3일
I've just added the license file.
Thanks for reminding me and thanks for your answer.
RMT
RMT 2021년 1월 3일
First of all, this DataHash file is yours and thanks for sharing that on FilesExchange.
In the second place, I've just modified my question to include a link to the FileExchange submissions as recommended. So did i reference it correctly? or there is a more common place for refrencing the FileExchange submissions?
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 3일
편집: Walter Roberson 2021년 1월 3일
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.
  댓글 수: 1
RMT
RMT 2021년 1월 3일
Thanks for your answer. Appreciated. And i usually look for your answer in the Matlab community because they are valuable. But the reason i chose to accept Jan's answer is that he mentioned something specific about the file sizes that i've missed in the first place (although intitutive but it just didn't come to my mind to check that when i had those different results).
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by