我曾经像这样在 Ruby 中生成数字签名:
def generate_signature
data = "Databeingpassed"
secret_key = "Somesecretkey"
digest = OpenSSL::Digest::Digest.new('sha256')
Base64.encode64(OpenSSL::HMAC.digest(digest, secret_key, data)).strip
end
Output: 2XBK7UXA9oDsfJj1TBE2maptpB6i1MJ4uadY1AXlQOQ=
如何用 Php 实现相同的,我在 php 中使用以下代码,但输出不同
function generate_signature() {
$data = "Databeingpassed"
$secret_key = "Somesecretkey"
$message = hash('sha256', $secret_key, $data);
return base64_encode($message);
}
Output: hgy/KMG3zTSgjUrzA/3nNvN+vApna6A7JqtZwx+r9Ng=
有任何想法吗?