title: How to use openssl_x509_parse and openssl_x509_verify on PHP
body: <p>I wanted to verify my certificate:</p>
  <p>In this PHP doc, we can see that <code>openssl_x509_verify</code> function must return 1: <a href="https://www.php.net/manual/fr/function.openssl-x509-verify.php" rel="nofollow noreferrer">https://www.php.net/manual/fr/function.openssl-x509-verify.php</a></p>
  <p>When I did this:</p>
  <pre><code>$certificate = base64_decode($payload['sca']); // I have certificate begin with &quot;-----BEGIN CERTIFICATE-----&quot;
  $chaincert = openssl_x509_read($certificate); // I have OpenSSL X.509 resource
  </code></pre>
  <p>Dump of <code>$chaincert</code>:
  <a href="https://i.stack.imgur.com/vMjeJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vMjeJ.png" alt="enter image description here" /></a></p>
  <p>Now I try to use the <code>openssl_x509_verify</code> function with parameters:</p>
  <ol>
  <li>$certificate</li>
  <li>$publicKey</li>
  </ol>
  <p>To get the public key, I do this:</p>
  <pre><code>$chainPublicKey = openssl_get_publickey($chaincert);
  </code></pre>
  <p>Then, I try:</p>
  <pre><code>$verify = openssl_x509_verify($chaincert, $chainPublicKey);
  </code></pre>
  <p>And, the result of $verify = <strong>0</strong>, not <strong>1</strong>.</p>
  <p>As the PHP documentation says ( <a href="https://www.php.net/manual/fr/function.openssl-x509-verify.php" rel="nofollow noreferrer">https://www.php.net/manual/fr/function.openssl-x509-verify.php</a> ), I must have a result equal to 1.</p>
  <p>Could you please help me?</p>
  <p>EDIT:</p>
  <p>I was able to solve my problem.
  My publicKey and my privateKey were not matching.</p>