Why HMAC sha256 return different value on PHP & Javascript

后端 未结 1 1408
日久生厌
日久生厌 2020-12-30 14:59

I am trying to build a HMAC SHA256 string in Javascript using CryptoJS, my existing code is written in PHP using the Akamai library.

In some cases I am getting diffe

相关标签:
1条回答
  • 2020-12-30 15:24

    CryptoJS add UTF8 encoding in "Key" while creating hash sha256 so that we are getting different value.

    If i wrap utf8_encode in PHP side then we will get same hmac value as compare to JavaScript

         // <php>
         $key = chr(63) . chr(23) . chr(253);
         signature3 = hash_hmac('SHA256', "st=1453362060~exp=1453363260~acl=/*", utf8_encode($key));
    
    0 讨论(0)
提交回复
热议问题