首页 > 解决方案 > PHP 等效于 openssl dgst -sha1 -hmac KEY -binary

问题描述

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

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

我尝试了 openssl_digest 和 openssl_encrypt 没有成功。我不明白参数的顺序...

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

谢谢你的帮助 !

标签: phpbashhashopensslsign

解决方案


bash 命令:

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

可以在 PHP 中解释如下:

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

推荐阅读