asmcrypto / asmcrypto.js

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

openssl dgst -sha256 != asmcrypto.SHA256.hex for the same string #116

Closed jsanta closed 7 years ago

jsanta commented 7 years ago

On my terminal: [12:58:46] → echo 'Hola mundo' | openssl dgst -sha256 9797b1e9be5a424f3f94392a8102a6c247a533d2d6e287d038c104f325e84fdb

On the browser: asmCrypto.SHA256.hex('Hola mundo') "ca8f60b2cc7f05837d98b208b57fb6481553fc5f1219d59618fd025002a66f5c"

Can't figure out if it's my mistake and I'm calling ther wrong method or if there's another setting for this to work as expected.

pohutukawa commented 7 years ago

That's obvious. echo appends a new line. Try this one:

echo -n 'Hola mundo' | openssl dgst -sha256
(stdin)= ca8f60b2cc7f05837d98b208b57fb6481553fc5f1219d59618fd025002a66f5c
jsanta commented 7 years ago

@pohutukawa didn't see it so obvious, but thanks :) I finally fixed this by retrieving my file and doing:

var _hash = new TextEncoder('UTF-8').encode(response.data);
_hash = asmCrypto.SHA256.hex(_hash);