title: Why can't I compute a correct HMAC signature?
body: <p>I am trying to compute an HMAC signature in Google Apps Script, but the documentation isn't 100% clear on how I need to pass in the parameters, and I have been unable to get the expected output.</p>
  
  <hr>
  
  <p>To determine if I am getting correct output, I am comparing the result against known-good PHP code. That code is:</p>
  
  <pre><code>$key = "a2V5"; # this is "key" base64-encoded
  $value = "test";
  $result = base64_encode(hash_hmac('sha512', $value, base64_decode($key), true));
  </code></pre>
  
  <hr>
  
  <p>My code in Google Apps Script is:</p>
  
  <pre><code>key = "a2V5"; // this is "key" base64-encoded
  value = "test";
  result = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, value, Utilities.base64Decode(key)));
  </code></pre>
  
  <p>The output I expected to receive was:</p>
  
  <pre><code>KHoPuJp/vfpbVThjaRjlN6W4MGXk/zMSaLeqoRXd4EepsPT7W4KGCPwLYyfxAFX3Y3sFjp4Nu55piQGj5t1GHA==
  </code></pre>
  
  <p>But what I got instead was:</p>
  
  <pre><code>mGXJ3X/nH5ZIFUAPtf1PsViY50pD3cfU7J8w2KAIEAqrAgZ3dpKcuy5V1yvH4/C5n1C9rFFsKc2JKHTwUqPscQ==
  </code></pre>
  
  <p>What did I screw up here?</p>