【问题标题】:AWS signature version 4 sha256 hash not signing correctly?AWS 签名版本 4 sha256 哈希未正确签名?
【发布时间】:2017-02-26 21:23:28
【问题描述】:

我正在尝试使用 AWS 签名版本 4 向 S3 提交请求。

当我提交请求时,我会收到消息 The request signature we calculated does not match the signature you provided. Check your key and signing method.

我不知道从这里去哪里。我尝试了几种不同的哈希算法(sha1、md5),但总是得到相同的响应。我已经验证了访问密钥和密钥。我刚刚在 AWS 上创建了一对新的,但仍然失败。

感谢任何帮助!

<?php
$date = date('Ymd');
$x_date = $date . "T000000Z";
$credential = AWS_ACCESS_KEY . '/' . $date . '/us-west-2/s3/aws4_request';
$redirect = 'https://roofscope.com/scope/thank-you';

$conditions = array(
	array('bucket' => 'tracescope'),
	array('starts-with', '$key', 'user/user1/'),
	array('acl' => 'public-read'),
	array('success_action_redirect' => $redirect),
	array("starts-with", "\$Content-Type", "image/"),
	array("x-amz-credential" => $credential),
	array("x-amz-algorithm"=> "AWS4-HMAC-SHA256"),
	array("x-amz-date" => $x_date),
);

$policy_b64 = $this->aws->getPolicy(3600 * 24, $conditions);
$signature = hash_hmac('sha256', $policy_b64, AWS_SECRET_KEY);
?>

<form action="http://tracescope.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
	<input type="input" name="key" value="test/${filename}"/><br/>
	<input type="hidden" name="acl" value="public-read"/>
	<input type="hidden" name="success_action_redirect" value="<?= $redirect; ?>"/>
	<input type="input" name="Content-Type" value="image/jpeg"/><br/>
	<input type="text" name="X-Amz-Credential" value="<?= $credential; ?>"/>
	<input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256"/>
	<input type="text" name="X-Amz-Date" value="<?= $x_date; ?>"/>
	<input type="hidden" name="Policy" value="<?= $policy_b64; ?>" />
	<input type="hidden" name="X-Amz-Signature" value="<?= $signature; ?>"/>

	<input type="file" name="file"/> <br/>

	<input type="submit" name="submit" value="Upload to Amazon S3"/>
</form>

【问题讨论】:

  • 我也遇到了这个问题,我尝试使用签名测试器并且签名(使用密钥)显示与我的代码生成的签名不同,但是当我在html 上传时遇到同样的错误...
  • 嗨,我遇到了与 ruby​​ 相同的问题。它使用 SHA1 对我有用。你可以看看我的question你用AWSv4上传成功了吗?

标签: php amazon-web-services amazon-s3 signature sha256


【解决方案1】:

尝试使用我的 s3 策略签名验证器。 请不要输入您的实际密钥。 使用示例键并在您身边测试示例键的计算。

http://ttwd80.github.io/s3postcalculatorverify/

有一个“显示/隐藏步骤”链接逐步解释了该过程。

【讨论】:

猜你喜欢
  • 2017-08-09
  • 1970-01-01
  • 2017-04-25
  • 1970-01-01
  • 2018-12-21
  • 1970-01-01
  • 2019-09-24
  • 2014-12-10
  • 2017-09-04
相关资源
最近更新 更多