bitwiseshiftleft / sjcl

Stanford Javascript Crypto Library
http://bitwiseshiftleft.github.com/sjcl/
Other
7.18k stars 986 forks source link

sha256 and utf8string from bit error #393

Open ngoclinhhoang opened 5 years ago

ngoclinhhoang commented 5 years ago

Hi guys,

I'm trying to get the hash sha256 value with utf8 string format. I expect linh@test.com will be come c0f50b4ab8bdd7bae3a6aff8278d3e96b07d0957541fdc1d4ad8c09680e00d5c with this line of code:

sjcl.codec.utf8String.fromBits(sjcl.hash.sha256.hash("linh@test.com"));

But, I receive this error message instead: sjcl.js:8 Uncaught TypeError: Cannot read property 'length' of undefined at Object.bitLength (sjcl.js:8) at sjcl.hash.sha256.update (sjcl.js:18)

Could you please help me to get the right value? Thank you Best Linh

robyoder commented 5 years ago

Your expected output is hexadecimal, not UTF-8. Change utf8String to hex.