asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
660 stars 182 forks source link

Different values depending on input type #74

Closed jvsteiner closed 9 years ago

jvsteiner commented 9 years ago

I am getting different hash values:

fr = new FileReader();
fr.readAsArrayBuffer(file);

asmCrypto.SHA256.hex(fr.results); //gets one answer from original ArrayBuffer
asmCrypto.SHA256.hex(new Uint8Array(fr.result)); // gets same answer when read into Uint8Array
asmCrypto.SHA256.hex(new ArrayBuffer(new Uint8Array(fr.result))); // gets different answer if I convert back into ArrayBuffer

shouldn't this work?

vibornoff commented 9 years ago

Nope it shouldn't. Take a look to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer

The result of new ArrayBuffer(new Uint8Array(fr.result)) is the same as for new ArrayBuffer(NaN).