为什么AWS4签名不匹配?

时间:2019-07-26 07:26:10

标签: amazon-web-services amazon-s3 electron-updater

我正在使用AWS4生成签名并传入请求标头。生成的签名未得到验证。

const opts = {
        service: 's3',
        region: 'region-name',
        method: 'GET',
        host: 's3-{region-name}.amazonaws.com',
        path: '/',
    };

我正在使用以下代码来生成签名

   var signature =  aws4.sign(opts, {
      accessKeyId: 'XXXXXX',
      secretAccessKey: 'XXXXXXXXXXXXXXXXXXXX',
    });

然后更新AutoUpdater(某些模块)的请求标头,最终导致aws出现。

autoUpdater.requestHeaders = signature.headers;

最后显示错误消息

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

是否有任何建议可以解决这个问题?

2 个答案:

答案 0 :(得分:0)

计算签名

1。使用UTF-8编码创建策略。

2。将UTF-8编码的策略转换为Base64。结果是要签名的字符串。

3。将签名创建为要签名的字符串的HMAC-SHA256哈希。您将提供签名密钥作为哈希函数的密钥。

4。使用十六进制编码对签名进行编码。

希望这会有所帮助。

谢谢 穆克什

答案 1 :(得分:0)

尝试一下:

request(aws4.sign({
hostname: 'test.amazonAPI.com',
service: 'execute-api',
region: 'us-east-1',
method: 'POST',
url: 'https://test.amazonAPI.com/test/doThing', // this field is not 
recommended in the document.
  body: load
 },
{
accessKeyId: tempCreds.Credentials.AccessKeyId,
secretAccessKey: tempCreds.Credentials.SecretAccessKey,
sessionToken: tempCreds.Credentials.SessionToken
}))