如何在 Laravel / PHP 中使用私钥对字符串 SHA256withRSA 进行签名?

问题描述 投票:0回答:1

调用API时需要发送签名,描述值为:

within asymmetric algorithm signature SHA256withRSA
(Private_Key, stringToSign). stringToSign = client_ID + “|” + X-TIMESTAMP

我的代码:

$timestamp = $this->x_timestamp;
$stringToSign = $this->client_id . '|' . $timestamp;
$privateKey = file_get_contents($this->private_key_path);
$privateKey = openssl_get_privatekey($privateKey);
openssl_sign($stringToSign, $signature, $privateKey, OPENSSL_ALGO_SHA256);
$signature = base64_encode($signature);

回复是

"Unauthorized. stringToSign"

我生成签名正确吗?

laravel openssl signature rsa-sha256
1个回答
0
投票

你得到这个问题的答案了吗?因为我正在解决同样的问题。我正在尝试访问 SNAP BI api。你要加密的字符串和我的一样。

© www.soinside.com 2019 - 2024. All rights reserved.