Trying to digitally sign via HMAC-SHA1 with PHP

前端 未结 3 589
梦如初夏
梦如初夏 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:43

    A php example is available at http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/UrlSigner.php-source

    0 讨论(0)
  • 2021-02-06 02:46

    I assume your trying to sign the url for OAuth?

    Try out this library: http://code.google.com/p/oauth/

    0 讨论(0)
  • 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), '+/', '-_');
    
    0 讨论(0)
提交回复
热议问题