How can I create a signature for AWS in Javascript?

痴心易碎 提交于 2019-12-11 01:52:06

问题


I am trying to create the signature for AWS Mechanical Turk, using Node.js, but am having trouble doing so. At the moment I am using the following, but keep getting errors:

CryptoJS.HmacSHA1(service + operation + timestamp, process.env.SECRET_ACCESS_KEY); 

The explanation of the signature is at this link. It states that to create a signature

A request signature, an HMAC, is calculated by concatenating the values of the Service, Operation, and Timestamp parameters, in that order, and then calculating an RFC 2104-compliant HMAC, using the Secret Access Key as the "key." The computed HMAC value should be base64 encoded, and is passed as the value of the Signature request parameter. For more information, go to http://www.faqs.org/rfcs/rfc2104.html.


回答1:


I think this will work for you (I use GetAccountBalance) as a simple example:

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha1.js"></script>  
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>  
<script>
var service = "AWSMechanicalTurkRequester";
var timestamp = new Date().toISOString();
var operation = "GetAccountBalance";
var secret = "YOURSECRETKEY";
var signature = CryptoJS.HmacSHA1(service + operation + timestamp, secret).toString(CryptoJS.enc.Base64);
</script>


来源:https://stackoverflow.com/questions/26915864/how-can-i-create-a-signature-for-aws-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!