0

I am using Node.js to read a file to bytedata (uint8array) and use SHA256 to hash the file’s bytedata like this:

ad505ee6067fba3f6fc20506d3379e190e087aeffe5d958ab9f2f3ed3800sa4f

I am wondering if it is possible or by any chance that for two different files having the same bytedata which might lead to the same SHA256 hash? Or what if same file but with very small change like the modification date, suffix or some other small change.

If so, is there any other practical way to get the unique identifier of a files in string?

Giacomo1968
  • 58,727
Neo Liu
  • 103

1 Answers1

1

I am curious that what about the file content will two files with different content by any chance have the same binary data

Generally, no. "Different content" literally means different "binary data". Those are the same thing – the data you read from a file is its whole content. The file's metadata such as file name, modification time, or extended attributes is not considered its "content".


(Files on NTFS on Windows might contain "alternate data streams" which behave more like whole files than extended attributes, but unlike macOS resource forks in the past, no Windows program spreads file content across multiple streams – non-main streams are only ever used as a way to hold extended attributes, so they can safely be considered metadata.)

grawity
  • 501,077