【发布时间】:2017-07-16 17:00:12
【问题描述】:
我需要帮助构建 Authorization 标头以 PUT 块 blob。
PUT\n\n\n11\n\n\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-date:Sat, 25 Feb 2017 22:20:13 GMT\nx-ms-version:2015-02-21\n/myaccountname/mycontainername/blob.txt\n
我接受这个,UTF 8 编码它。然后我在我的 Azure 帐户中使用我的访问密钥,并用密钥对这个 UTF 8 编码字符串进行 HMAC sha256。然后我在base64中输出。我们称之为输出字符串。
我的授权标头如下所示:SharedKey myaccountname:output string
它不工作。
Postman 中的标头也有 x-ms-blob-type、x-ms-date、x-ms-version、Content-Length 和 Authorization。身体现在说你好世界。
谁能帮我在 Postman 中成功提出这个请求?
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:cdeb9a5e-0001-0029-5fb5-8f7995000000
Time:2017-02-25T22:22:32.0300016Z</Message>
<AuthenticationErrorDetail>The MAC signature found in the HTTP request 'jiJtirohvi1syXulqkPKESnmQEJI4GpDU5JBn7BM/xY=' is not the same as any computed signature. Server used following string to sign: 'PUT
11
text/plain;charset=UTF-8
x-ms-date:Sat, 25 Feb 2017 22:20:13 GMT
x-ms-version:2015-02-21
/myaccountname/mycontainername/blob.txt'.</AuthenticationErrorDetail>
</Error>
编辑:
首先,我要感谢您和所有回复的人。我真的很感激。我有最后一个问题,然后我想我会准备好的!!我没有使用那个代码——我都是手工完成的。如果我有我的密钥:X2iiy6v47j1jZZH5555555555zzQRrIAdxxVs55555555555av8uBUNGcBMotmS7tDqas14gU5O/w== 因匿名而略有更改 - 我是否对其进行解码:使用在线 base64decoder。然后,当我的字符串现在看起来像这样时:PUT\n\n\n11\n\ntext/plain;charset=UTF-8\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-date:Mon, 27 Feb 2017 21:53:13 GMT\nx-ms-version:2015-02-21\n/myaccount/mycontainer/blob.txt\n 所以我在https://mothereff.in/utf-8 中运行它,然后在 HMAC 中使用我的解码密钥:https://www.liavaag.org/English/SHA-Generator/HMAC/ - 最后使用 sha256 和 base64。
这就是我将正确的字符串放在这里的方式吗?:SharedKey myaccount:<string here>
【问题讨论】:
-
使用您提到的生成代码的工具由于“\n”字符而与签名不匹配。我写了一个online tool 来生成签名。我也更新了答案。
标签: api azure azure-blob-storage