I encounter an odd issue when I calculate SHA256 checksums in Javascript. I use the following code:
const hashBuffer = await window.crypto.subtle.digest("SHA-256", arrayBuffer)
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
Afterwars I transfer the data to a server, that calculates the checksum for the data to check integrity, using the same code. Both client and Server run on the same machine. Here is the issue:
On the client, for some files, the checksum changes upon every calculation, whereas for others the checksum stays consistent. On the server, the calculations are all consistent.
I do not change the files during calculations. I do not even touch them. I was thinking that maybe the metadata could change upon calculations, that when the file gets 'touched' by the browser/javascript FileReader, but then again for many files the checksum is consistent, and I transfer the full data to the server, so it would include the metadata (as both are running on the same system, that is).
I wonder what could be the cause. Maybe there are weired security mechanisms in browsers that obscure the file in a way? Or maybe any other reason... I would like to keep the integrity check, as it is crucial for security and stability, but as for now, this is a big issue.
I have found different information on the internet, e.g. someone encountered this issue with a corrupted memory. But again, the calculations happen on the same machine, and the checksums are consistent on the server after the transfer (as in "the data did not change between runs", but the checksum does..)
I hope this is the right place to ask. This may be more a developers/javascript issue. However.. If you have any ideas what the reason could be, or how to debug this, please let me know.