php - 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 中生成预期的命令吗?
谢谢你的帮助 !
解决方案
bash 命令:
password='echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64'
可以在 PHP 中解释如下:
$password = base64_encode(hash_hmac('sha1', $date, $apiKey, true));
推荐阅读
- reactjs - 如果项目在本机反应中为零,如何检查平面列表
- android - 在警报对话框中显示 tablayout
- node.js - 按 DESC 性能排序的 Sqlite
- javascript - 使用生成的 ID 删除 Json 数据
- excel - OpenXML - 继续写入下一个工作表(百万行命中)
- laravel - SPA 使用 Laravel 5.8 / Vue - auth() 返回令牌 true 而不是令牌值
- java - 无法创建 Java 虚拟机 javaw.exe。我的世界
- java - 使用 JNI 从 Android 应用程序向 C++ 发送字符串
- java - Map-Reduce 中的洗牌
- java - Java UTF-8 URLEncoder 编码不应该的特殊字符