Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsSHA SHA-1 nodejs wrong hashed result #14

Closed
makepanic opened this issue Dec 29, 2013 · 3 comments
Closed

jsSHA SHA-1 nodejs wrong hashed result #14

makepanic opened this issue Dec 29, 2013 · 3 comments

Comments

@makepanic
Copy link

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 👍

@Caligatio
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants