如何使用Javascript为AWS创建签名? [英] How can I create a signature for AWS in Javascript?

查看:178
本文介绍了如何使用Javascript为AWS创建签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Node.js为AWS Mechanical Turk创建签名,但是这样做很麻烦.目前,我正在使用以下内容,但仍会出现错误:

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

请求签名,即HMAC,是通过将 Service,Operation和Timestamp参数的值 顺序,然后使用 秘密访问密钥作为密钥".计算出的HMAC值应为 base64编码,并作为签名请求的值传递 范围.有关更多信息,请访问 http://www.faqs.org/rfcs/rfc2104.html .

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.

推荐答案

我认为这很适合您(我使用GetAccountBalance)作为一个简单示例:

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>

这篇关于如何使用Javascript为AWS创建签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆