aws签名版本4签名密钥问题ruby

mbjcgjjk  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(281)

必须在ruby中完成我的代码是:

require "openssl"
require "time"
require "uri"
require "pathname"

def getSignatureKey (key, dateStamp, regionName, serviceName)
  digest= OpenSSL::Digest.new('sha256')
  kDate = OpenSSL::HMAC.hexdigest(digest, ("AWS4" + key), dateStamp)
  puts("kdate:  #{kDate}")
  kRegion = OpenSSL::HMAC.hexdigest(digest, kDate, regionName)
  puts("kRegion:  #{kRegion}")
  kService = OpenSSL::HMAC.hexdigest(digest, kRegion, serviceName)
  puts("kService:  #{kService}")
  kSigning = OpenSSL::HMAC.hexdigest(digest, kService, "aws4_request")
  puts("kSigning:  #{kSigning}")
  kSigning
end

key = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'
dateStamp = '20120215'
regionName = 'us-east-1'
serviceName = 'iam'

puts("===========================================OUTPUT IS: ==============================================")
getSignatureKey(key,dateStamp,regionName,serviceName)

它产生输出:
kdate:969FBB94FEB542B71EDE6F87FE4D5FA29C789342B0F4074670F0C2489E0A0D kregion:A59E30F9D899C47B3D68EA1C0AB529E03A8F4ED2F54CB64AF547330A22A0服务:E33CBCDA009243ED24C04AF249A477D33C97BA7717327636AFAB6E6EF78 K签名:9D8A8749E911A4D00ED2F4F4F4CF26902B4BD028EBD8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D8D
但是,根据aws文件,输出应为:https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html):
kdate:969FBB94FEB542B71EDE6F87FE4D5FA29C789342B0F4074670F0C2489E0A0D kregion:69daa0209cd9c5ff5c8ced464a696fd4252e981430b10e3d3fd8e2f197d7a70c K服务:F72CFDD46F26C4643F06A11EABB6C0BA18780C19ACE671265E3C87FA K签名:F470E2D9FFA895F9C67B32B190A4
所以kdate匹配,但其他的不匹配,我没有错过拼写“us-east-1”,所以我真的不知道为什么它们不匹配。如果有人能提供建议,我将不胜感激。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题