Unable to reproduce AWS signature from example using HMAC SHA256

后端 未结 2 475
既然无缘
既然无缘 2021-01-24 22:45

I am following this example

http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html

and trying to reproduce the 64 character string for the

相关标签:
2条回答
  • 2021-01-24 22:48

    I can't tell from your post but those are quite possibly exactly the same results, formatted differently.

    Your code returns the raw result of the HMAC operation - this is arbitrary binary data so it's not going to print as anything readable. Amazon expect you to provide the hex representation for each byte: your first couple of bytes are "\xae\xee" instead of "aeee"

    The easiest way to do this is call hexdigest rather than digest. Note that you should only do this for the final HMAC (when you sign the string to sign with the signing key) not when constructing the signing key

    0 讨论(0)
  • 2021-01-24 23:02

    It's possible that your "strange sequence of characters" is in fact the correct output.

    OpenSSL::HMAC.digest spits out a value represented in binary, and you are comparing that to a value represented in hex

    Check to see what happens when you print out the signature after converting it to hex representation like so:

    signature.each_byte.map { |b| "%02x" % b }.join
    
    0 讨论(0)
提交回复
热议问题