![](/img/trans.png)
[英]openssl_verify(): supplied key param cannot be coerced into a public key
[英]openssl_verify(): supplied key param cannot be coerced into a public key for a .pem file
當前正在嘗試讀取.pem
公鑰以通過openssl
對其進行驗證。
/**
* Check whether the signed message sent back by the server is
* correct or not.
*/
function check($str, $MAC)
{
$fp = fopen(
dirname(__FILE__) . '/rsa_public_key.pem',
'r'
);
$cert = fread($fp, 8192);
fclose($fp);
$pubkeyid = openssl_get_publickey($cert);
return openssl_verify($str, $MAC, $pubkeyid);
}
話雖如此,在執行我的腳本時,我收到此錯誤:
openssl_verify(): supplied key param cannot be coerced into a public key in some/path at line X
本來,我寫這個函數是為了接受.cer
認證。 以下是對所有這些不同密鑰格式之間差異的解釋。 據我了解.pem
類似於.cer
,但是,我.cer
其一生都無法弄清楚如何讓我的腳本讀取我的.pem
文件。
我的問題是 - 我需要做什么才能讓我的函數讀取這個公鑰?
編輯:在谷歌搜索時,我嘗試使用file_get_contents()
到特定路徑,但我會收到相同的錯誤。
什么可能導致此錯誤?
打開這個.pem
文件后,所有內容都在一行中。 看起來每行需要 64 個字符的長度,所以我確保每行都是 64 行,並且成功解析。 與.cer
無關。
此外, -----BEGIN PUBLIC KEY-----
和-----END PUBLIC KEY-----
行每邊應包含正好五個破折號。 不多也不少。 六個就出來了。
最后一行的末尾可能有也可能沒有換行符。
允許使用 Windows 行結尾 (CR/LF),即使在 *nix 托管的 PHP 上也是如此。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.