我试图计算在谷歌Apps脚本的HMAC签名,但文档是如何,我需要在参数传递不是100%清楚,我一直无法得到预期的输出。
如果要判断我得到正确的输出,我比较反对已知良好的PHP代码的结果。 这代码是:
$key = "a2V5"; # this is "key" base64-encoded
$value = "test";
$result = base64_encode(hash_hmac('sha512', $value, base64_decode($key), true));
我在谷歌Apps脚本代码是:
key = "a2V5"; // this is "key" base64-encoded
value = "test";
result = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, value, Utilities.base64Decode(key)));
我希望得到的输出是:
KHoPuJp/vfpbVThjaRjlN6W4MGXk/zMSaLeqoRXd4EepsPT7W4KGCPwLYyfxAFX3Y3sFjp4Nu55piQGj5t1GHA==
但我得到的却是:
mGXJ3X/nH5ZIFUAPtf1PsViY50pD3cfU7J8w2KAIEAqrAgZ3dpKcuy5V1yvH4/C5n1C9rFFsKc2JKHTwUqPscQ==
我是怎么搞砸了这里?