【问题标题】:PHP equivalent of openssl dgst -sha1 -hmac KEY -binaryPHP 等效于 openssl dgst -sha1 -hmac KEY -binary
【发布时间】:2020-10-05 09:06:35
【问题描述】:

我尝试在 PHP 中实现这个 bash 命令但没有成功:

password='echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64'

我尝试了 openssl_digest 和 openssl_encrypt 都没有成功。 看不懂参数的顺序……

您能帮我在 PHP 中生成预期的命令吗?

感谢您的帮助!

【问题讨论】:

  • 基本上不就是hash_hmac()吗?
  • 感谢您的回答,我试过了:$password = base64_encode(hash_hmac('sha1', $date, $apiKey, true)); 但这似乎行不通
  • 我无法重现这个,这两个结果在我的机器上是相同的。也许您应该发布一个具体示例,其中包含已定义的输入值(日期、apiKey)以及 bash 和 PHP 的结果。
  • 感谢您的回答。 hash_hmac 是正确的使用方法,下一个问题来自使用 GuzzleHttp\Client

标签: php bash hash openssl sign


【解决方案1】:

bash 命令:

password='echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64'

在 PHP 中可以这样解释:

$password = base64_encode(hash_hmac('sha1', $date, $apiKey, true));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    相关资源
    最近更新 更多