Ruby 这是腾讯的加密步骤,怎么用 Ruby 做出来?

bill997603 · October 30, 2019 · Last by sevk replied at October 30, 2019 · 5223 hits

请求正文(payload,即 body,此示例为 {"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]})的哈希值,计算伪代码为 Lowercase(HexEncode(Hash.SHA256(RequestPayload))),即对 HTTP 请求正文做 SHA256 哈希,然后十六进制编码,最后编码串转换成小写字母。对于 GET 请求,RequestPayload 固定为空字符串。此示例计算结果是 35e9c5b0e3ae67532d3c9f17ead6c90222632e5b1ff7f6e89887f1398934f064

require 'digest'

s = '{"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]}'

print Digest::SHA2.new(256).hexdigest(s).downcase

bill997603 closed this topic. 31 Oct 10:29
bill997603 closed this topic. 31 Oct 10:29
You need to Sign in before reply, if you don't have an account, please Sign up first.