验证通知签名 (PHP)

发布于 2024-09-07 00:54:14 字数 484 浏览 3 评论 0原文

我需要验证来自 ankoder.com 的回调签名,该回调提供以下描述:

它是私钥的 Base64 编码 HMAC-SHA1 摘要的 URL 转义字符串和 URL 未转义消息。

$passkey = urlencode(base64_encode(hash_hmac('sha1', urldecode($str), $private_key, true)));

他们提供了以下 Ruby 示例,

encoded_signature = CGI.escape Base64.encode64(HMAC::SHA1::digest(private_key, CGI.unescape(message))).strip

我在从回调返回的示例数据上运行此示例,但没有获得相同的签名。如何在 PHP 中复制 Ruby 代码?

编辑 问题是发送的尾随空格。

I need to validate a signature for a callback from ankoder.com who provide the following description:

It is the URL-escaped string of Base64-encoded HMAC-SHA1 digest of your private key and the URL-unescaped message.

$passkey = urlencode(base64_encode(hash_hmac('sha1', urldecode($str), $private_key, true)));

They provide the following Ruby example

encoded_signature = CGI.escape Base64.encode64(HMAC::SHA1::digest(private_key, CGI.unescape(message))).strip

I run this on sample data I have returned from a callback but am not getting the same signature. How do I replicate the Ruby code in PHP?

Edit
The issue was trailing whitespace being sent through.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-09-14 00:54:14

您的 PHP 代码与 Ruby 代码相匹配。问题一定出在其他地方。

检查密钥是否正确以及消息是否正确解析(urldecode,然后 json_decode)。

Your PHP code matches the Ruby code. The problem must be somewhere else.

Check if the key is correct and the message is parsed correctly (urldecode, then json_decode).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文