title: Trying to digitally sign via HMAC-SHA1 with PHP
body: <p>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# and Java code to show you how to do the signature via HMAC-SHA1. There is also an example so that I can to test my PHP implementation. However, I just can't seem to get it to work.   </p>
  
  <p>Here's my code:</p>
  
  <pre><code>$key = "vNIXE0xscrmjlyV-12Nj_BvUPaw=";
  
  $data = "/maps/api/geocode/json?address=New+York&amp;sensor=false&amp;client=clientID";
  
  $my_sign = hash_hmac("sha1", $data, base64_decode($key));
  $my_sign = base64_encode($my_sign);
  
  $valid_sign = "KrU1TzVQM7Ur0i8i7K3huiw3MsA=";
  </code></pre>
  
  <p>When, I run this, I get a signature of:</p>
  
  <pre><code>ZDRlNGMwZjIyMTA1MWM1Zjk0Nzc4M2NkYjlmNDQzNDBkYzk4NDI4Zg==
  </code></pre>
  
  <p>Which totally doesn't match. </p>
  
  <p>Things I have thought about:</p>
  
  <ol>
  <li>The key is in Modified URL encoded format, so changing <code>-</code> and <code>_</code> to <code>+</code> and <code>/</code> also doesn't work</li>
  <li>The Python example code does indeed work, so this is a valid example.</li>
  <li>Completely rewriting our code-base in python instead of PHP (I inherited it).</li>
  </ol>