计算 HMAC-SHA 签名
我正在为 Amazon 的 SimpleDB 编写一个模块。它们要求使用 HMAC-SHA 算法对 REST 请求进行签名。 (详细信息请参见此处。)
我被告知有是计算此签名的函数,但我在 文档。该函数被称为什么?它的参数是什么样的?
I'm writing a module for Amazon's SimpleDB. They require REST requests to be signed using HMAC-SHA algorithm. (Details here.)
I'm told that there is a function to computer this signature, but I can't find it in the documentation. What is the function called, and what do its arguments look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:以下内容应该有效:
函数为
math:hmac_sha256_base64(,)
EDITED: The following should work:
The function is
math:hmac_sha256_base64(<datastring>,<keystring>)
HMAC 是一个标准函数,可以在大多数平台的加密库中找到。亚马逊在您链接到的文档页面上显示了几个示例。
对于 Java,您可以在 javax.crypto 中找到它.Mac
对于 .Net,请查看系统.Security.Cryptography
对于KRL,我还没有找到任何内置的库存解决方案。由于嵌入 javascript 似乎是可能的,因此 jsSHA 实现可能会很有用。数学库中有一个sha1函数,并根据RFC2104似乎并不那么困难。
The HMAC is a standard function that can be found in crypto libraries for most platforms. Amazon shows several examples on the documentaion page you link to.
For Java, you can find it in javax.crypto.Mac
For .Net, look in System.Security.Cryptography
For KRL, I haven't found any built-in stock solution. Since it seems possible to embed javascript, the jsSHA implemenation could be useful. There is a sha1 function in the math library, and implementing HMAC according to RFC2104 doesn't seem that difficult.
要使用嵌入的换行符对字符串进行签名(AWS 我在跟你说话!),您必须执行以下操作(基于 AWS S3 示例)
uri:decode()
函数返回带有正确换行符的字符串,其中\n\n\n
没有。您可能需要在签名中添加尾随“=”。To sign strings with embedded newlines (AWS I'm talking to you!) you have to do the following (based on the AWS S3 example)
The
uri:decode()
function returns a string with proper newlines, where\n\n\n
does not. You might have to add trailing '=' to the signature.