title: openssl_verify(): supplied key param cannot be coerced into a public key for a .pem file
body: <p>Currently attempting to read a <code>.pem</code> public key to verify it through <code>openssl</code>.</p>
  
  <pre><code>/**
   * 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);
  }
  </code></pre>
  
  <p>With that said, upon executing my script, I receive this error:</p>
  
  <p><code>openssl_verify(): supplied key param cannot be coerced into a public key in some/path at line X</code></p>
  
  <p>Originally, I wrote this function to accept <code>.cer</code> certifications. Here's an explanation of the difference between all these <a href="https://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file">different key formats</a>. To my understanding <code>.pem</code> are similar to <code>.cer</code>, however, I could not for the life of me figure out how to allow my script to read my <code>.pem</code> file.</p>
  
  <p>My question is - what do I need to do in order for my function to read this public key?</p>
  
  <p>EDIT: Upon some Googling, I have tried using <code>file_get_contents()</code> to a particular path but I would receive the same error. </p>
  
  <p>What could be causing this error?</p>