我正在研究 AS3 分段上传器。我正在使用此文档http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html来构建签名。这是我的例子:
要求:
POST /btnOK.png?uploads HTTP/1.1
Referer: app:/Main.swf
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, */*;q=0.5
x-flash-version: 10,1,53,64
Date: Thu, 23 Jun 2011 09:03:18 GMT
Authorization: AWS accesskey:signature
Content-Type: image/png
User-Agent: Mozilla/5.0 (Windows; U; en-US) AppleWebKit/531.9 (KHTML, like Gecko) AdobeAIR/2.0.2
Host: bucketname.s3.amazonaws.com
Content-Length: 0
Connection: Keep-Alive
未签名文本:
POST\n
\n
image/png\n
Thu, 23 Jun 2011 09:03:18 GMT
/bucketname/btnOK.png?uploads
我收到以下错误响应: SignatureDoesNotMatch:我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。
未签名文本中是否缺少某些标题?也许Referer,Accept等应该在未签名的文本中?
我在 JavaScript ( http://aws.amazon.com/code/199 ) 中使用了 Amazon S3 签名测试器,并且得到了相同的未签名文本。也许问题出在加密上?我正在使用 as3crypto 库。这是我的 AS3 代码:
private function generateSignature(datas:String, securityKey:String):String {
var sha:SHA1 = new SHA1();
var securityKeyArray:ByteArray = new ByteArray();
securityKeyArray.writeUTFBytes(escape(securityKey));
sha.hash(securityKeyArray);
var hmac:HMAC = new HMAC(sha);
var datasArray:ByteArray = new ByteArray();
datasArray.writeUTFBytes(escape(datas));
var signatureArray:ByteArray = new ByteArray();
signatureArray = hmac.compute(securityKeyArray, datasArray);
return Base64.encodeByteArray(signatureArray);
}
请帮忙!谢谢!