Skip to content Skip to sidebar Skip to footer

Match Php And Cryptojs Output

I cannot find the solution to the reverse of the linked question, and have tested it the same way. php and javascript are giving different values because of certain characters. T

Solution 1:

As per the link you included in your question. CryptoJS interprets strings as UTF-8. The character ý is two bytes in UTF-8 chr(195).chr(189), so your JavaScript is equivalent to hashing the PHP string 'test'.chr(195).chr(189).

To get the PHP result in JavaScript, you will need to parse the array to a Cypto.lib.WordArray using the encoding you want (Latin1) manually instead so that it doesn't assume UTF-8:

var test = CryptoJS.enc.Latin1.parse( 'test'+String.fromCharCode(253) );
// oMb9XiT7Y18wYJ7m0kOaIebZrS7eY+/odXmHLq5xPjRVbNfdcwBYQGycRKQ0n7EgqFmF+Ul3oucJHH2AK/IYLw==

Post a Comment for "Match Php And Cryptojs Output"