Differing Sha1 Hashes For Identical Values On The Server And The Client
On the client I'm using Rusha, which I've put into a wrapper: function cSHA1(m){ return (new Rusha).digest(m); } On the server I'm using Node's native crypto module, function sS
Solution 1:
I have run into the same problem with the German Umlaut character when comparing SHA1 hashes of PHPs sha1 and Rusha.
The reason is simple: some stoned fool decided Javascript strings are UTF16 - and PHP doesn't give a sh*t about encoding, it just takes what is there. So, if you supply PHP a json_decode("\u00e4"), it will turn this into a 2-byte string 0xc3 0xa4 (UTF8).
JS instead will make a single UTF16 byte out of this (0xE4) - and Rusha's manual explicitly says all codepoints must be below 256.
To help yourself, use the UTF18-to-8 library at http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt like sha.digest(utf16to8("\u00e4"))
. This will feed rusha correct codepoints.
Post a Comment for "Differing Sha1 Hashes For Identical Values On The Server And The Client"