gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:45:57 26 4
gpt4 key购买 nike

我在浏览亚马逊产品广告 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com