ruby - 使用 ruby​​ 中的 SHA256 哈希算法计算符合 RFC 2104 的 HMAC

标签 ruby amazon amazon-product-api

我在浏览亚马逊产品广告 API REST signature docs 时卡在了#8

Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm using the string above with our "dummy" Secret Access Key: 1234567890. For more information about this step, see documentation and code samples for your programming language.

没关系,在 Calculating a SHA hash with a string + secret key in python 的帮助下再次尝试成功。将在下面发布答案。

最佳答案

以下创建正确的签名:

require 'openssl'

secret_key = '1234567890'
query = 'AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&Version=2009-01-06'
data = ['GET', 'ecs.amazonaws.com', '/onca/xml', query].join("\n")
sha256 = OpenSSL::Digest::SHA256.new
sig = OpenSSL::HMAC.digest(sha256, secret_key, data)
signature = Base64.encode64(sig)

关于ruby - 使用 ruby​​ 中的 SHA256 哈希算法计算符合 RFC 2104 的 HMAC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16599436/

相关文章:

amazon-web-services - 亚马逊产品 api 获取库存可用性(有货、缺货等)

php - 未获取产品广告 API AWS 的促销摘要

Ruby 多字符串替换

ruby - 如何将 Base64 图像发送到 Ruby 中的 Google Cloud Vision API 标签检测?

ruby - 引导 AWS 服务器时 Ruby Fog 的超时问题

android - 使 AndroidTV 应用程序可在 FireTV 上运行

mod-rewrite - S3 上带有 Backbone 前端的深层链接

python - 导入错误 : No module named lxml - Even though LXML Is installed

ruby-on-rails - 在 Ruby on Rails 部分中渲染 React 组件

android - 如何在 Mac 上使用 Eclipse 调试 Amazon Kindle Fire 上的应用程序?