indutny / hash.js

Hash functions in pure javascript
317 stars 42 forks source link

Incorrect hash generated when binary data is supplied using a binary string. #24

Open jordanmack opened 5 years ago

jordanmack commented 5 years ago

An incorrect hash is may be generated if a binary string is used. In my case, I was obtaining the string from a FileReader instance's readAsBinaryString() method. It seems to work fine with text files, but binary files throw it off and silently give the wrong hash. Using the recommended method of readAsArrayBuffer() works fine as long as you convert it to Uint8Array before passing it to the hasher via update().