Caligatio / jsSHA

A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.
https://caligatio.github.io/jsSHA/
BSD 3-Clause "New" or "Revised" License
2.23k stars 394 forks source link

jsSHA SHA-1 nodejs wrong hashed result #14

Closed makepanic closed 10 years ago

makepanic commented 10 years ago

I've tried to use the jsSHA SHA-1 implementation in node but had a weird bug. An earlier implementation of the same method in the browser works as expected.

I wrote a small nodeunit test that uses jsSHA and node crypto to hash the same input.

Running the script in nodeunit I get:

Expected :"B153C0D8C766A64F677A3D1797E680D18EC571DD"
Actual   :"FF620005437AB0686DEF9D889D732B902B8A4B98"

If there's something wrong with the implementation just tell me :+1:

Caligatio commented 10 years ago

Reading your script, you have a function called hex2bin and you pass its output to jsSHA with type "TEXT" If you just pass the string as-is (without hex2bin) and set its type to "HEX" you should be set.

makepanic commented 10 years ago

Thanks it now works fine. The strange thing is that using the pastebin implementation of jsSha in the browser it works fine:

https://github.com/makepanic/globe/blob/master/src/js/helpers/util.js#L23

guess this can be closed

Caligatio commented 10 years ago

I honestly have no idea how it would have worked in the browser as it is currently written.

It looks like you may be using a slightly order version of the library. The most recently version (1.5) has slightly better Node support and I shrunk the file size quite a bit. Also, it has the ability to output uppercase HEX strings.

Let me know if you have any more problems!