开发者

SHA1 hmac PHP vs Javascript - Different Results?

Hello I am using class in javascript to hash string: https://ssl.bsk.com.pl/mobi/js/sha1.js

hex_hmac_sha1("927545161", "asdasdasdasdś") ;

Result is: 5db0194c834d419fc5d68b72c88af1ac8ee749d6

In PHP i'm hashing:

echo hash_hmac('sha1', "asdasdasdasdś", '9开发者_JAVA百科27545161');

but result is: 0b115775a20bed9922b6a9cc934cb5328fe71ade

Where is error? 5db0194c834d419fc5d68b72c88af1ac8ee749d6 != 0b115775a20bed9922b6a9cc934cb5328fe71ade


PHP interprets the UTF-8 string as sequence of 8-bit chars. Whereas in Javascript each character can resolve to an Unicode code point.

Your compacted and totally unreadable Javascript implementation uses .charCodeAt() to transform the string into a hexstring. I didn't bother to investigate it completely, but it's most likely that "ś".charCodeAt(0) simply resolves to 347, and the remainder of the conversion expected a value in the 8-bit range 0 to 255.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜