Trying to digitally sign via HMAC-SHA1 with PHP

前端 未结 3 627
梦如初夏
梦如初夏 2021-02-06 02:25

I\'m trying to setup some Google Maps Premier API action, and to do so, I need to sign my URLs to authenticate. If you go down to Signature examples, there is some Python, C# an

3条回答
  •  时光取名叫无心
    2021-02-06 02:58

    You have 2 problems at least,

    1. The Google uses special URL-safe Base64. Normal base64_decode doesn't work.
    2. You need to generate the SHA1 in binary.

    Try this,

    $key = "vNIXE0xscrmjlyV-12Nj_BvUPaw=";
    $data = "/maps/api/geocode/json?address=New+York&sensor=false&client=clientID";
    $my_sign = hash_hmac("sha1", $data, base64_decode(strtr($key, '-_', '+/')), true);
    $my_sign = strtr(base64_encode($my_sign), '+/', '-_');
    

提交回复
热议问题