h2non / jshashes

Fast and dependency-free cryptographic hashing library for node.js and browsers (supports MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base64 decode doesn't give correct result

ovk opened this issue · comments

commented

Please see this small example: https://jsfiddle.net/j1rp55oo/

You can check that Base64.encode(...) works correctly by decoding it's output using OpenSSL or any other base64 encoder. Base64.decode(...) on the other hand, returns complete garbage.

I'm not at a computer for the rest of the weekend but base64 encoding/decoding can be performed natively by browsers by using atob and btoa.

commented

Thanks, I know about atob/btoa, but it's not supported in IE9, unfortuntely. So having working base64 encoding in jshashes still could be useful.

Yeah, that's a problem.

It should use i++ here: https://github.com/h2non/jshashes/blob/master/hashes.js#L331~L334 .
Then decode works for ASCII words.

We should update the input length after UTF-8 convert: https://github.com/h2non/jshashes/blob/master/hashes.js#L301.
Then encode works for UTF-8 words