Currently trying to read the .pem public key in order to verify it through openssl .
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, after running my script, I get this error:
openssl_verify(): supplied key param cannot be coerced into a public key in some/path at line X
I originally wrote this function to accept .cer certificates. This explains the difference between all of these different key formats . As far as I understand, .pem similar to .cer , however I couldn’t understand all my life how to allow my script to read my .pem file.
My question is: what do I need to make my function read this public key?
EDIT: After some Googling, I tried using file_get_contents() for a specific path, but I would get the same error.
What can cause this error?
source share