openssl_verify():提供的密钥参数不能强制为.pem文件的公共密钥 [英] openssl_verify(): supplied key param cannot be coerced into a public key for a .pem file
问题描述
当前正在尝试读取.pem
公钥以通过openssl
对其进行验证.
Currently attempting to read a .pem
public key to verify it through 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);
}
话虽如此,执行脚本后,我收到此错误:
With that said, upon executing my script, I receive this error:
openssl_verify(): supplied key param cannot be coerced into a public key in some/path at line X
Originally, I wrote this function to accept .cer
certifications. Here's an explanation of the difference between all these different key formats. To my understanding .pem
are similar to .cer
, however, I could not for the life of me figure out how to allow my script to read my .pem
file.
我的问题是-为了使我的功能读取此公钥,我需要做什么?
My question is - what do I need to do in order for my function to read this public key?
在进行一些谷歌搜索时,我尝试使用file_get_contents()
到特定路径,但是会收到相同的错误.
Upon some Googling, I have tried using file_get_contents()
to a particular path but I would receive the same error.
什么可能导致此错误?
推荐答案
打开此.pem
文件后,它们全部放在一行中.看来每一行都需要64个字符的长度,因此我确保每一行都是64行,并且可以成功解析.与.cer
无关.
Upon opening this .pem
file, it was all in one line. It appears each line requires the length of 64 characters, so I made sure each line was 64 lines, and it successfully parsed. Had nothing to do with .cer
.
这篇关于openssl_verify():提供的密钥参数不能强制为.pem文件的公共密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!