title: Signing data gives mismatch using openssl_sign and openssl_verify
body: <p>The last few days I'm trying to produce a signature on XML data by using <code>openssl_sign</code> and later verify this by using <code>openssl_verify</code>. Unfortunately <code>openssl_verify</code> keeps returning false. Since I was not sure if my private and public key extracted from my certificate were OK, I also tried <a href="http://php.net/manual/en/function.openssl-sign.php#77571" rel="nofollow noreferrer">a basic example</a>. </p>
  
  <p><code>openssl_sign</code> indeed returns a binary signature. So far so good (also did this with my private key extracted from PEM cert). Also in the example <code>openssl_verify</code> returns false. I Assume that the private and public keys are correct in the example. Any help in how to sign and verify?  </p>
  
  <pre><code>&lt;?php
  $Data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  // $key_private_id = openssl_get_privatekey(file_get_contents($ClientCertFile), $passphrase);
  // $key_public_id = openssl_get_publickey(file_get_contents($ClientCertFile));
  
  $key_private_id = &lt;&lt;&lt;EOD
  -----BEGIN RSA PRIVATE KEY-----
  MIIBOgIBAAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6zxqlVzz0wy2j4kQVUC4Z
  RZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQJAL151ZeMKHEU2c1qdRKS9
  sTxCcc2pVwoAGVzRccNX16tfmCf8FjxuM3WmLdsPxYoHrwb1LFNxiNk1MXrxjH3R
  6QIhAPB7edmcjH4bhMaJBztcbNE1VRCEi/bisAwiPPMq9/2nAiEA3lyc5+f6DEIJ
  h1y6BWkdVULDSM+jpi1XiV/DevxuijMCIQCAEPGqHsF+4v7Jj+3HAgh9PU6otj2n
  Y79nJtCYmvhoHwIgNDePaS4inApN7omp7WdXyhPZhBmulnGDYvEoGJN66d0CIHra
  I2SvDkQ5CmrzkW5qPaE2oO7BSqAhRZxiYpZFb5CI
  -----END RSA PRIVATE KEY-----
  EOD;    
  
  
  $key_public_id = &lt;&lt;&lt;EOD
  -----BEGIN PUBLIC KEY-----
  MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANDiE2+Xi/WnO+s120NiiJhNyIButVu6
  zxqlVzz0wy2j4kQVUC4ZRZD80IY+4wIiX2YxKBZKGnd2TtPkcJ/ljkUCAwEAAQ==
  -----END PUBLIC KEY-----
  EOD;
  
  if(!openssl_sign($Data, $Signature, $key_private_id, OPENSSL_ALGO_SHA1 )) { 
      echo "Failed to sign data: $Data ";
  }
  
  if(!openssl_verify($Data, $Signature, $key_public_id, OPENSSL_ALGO_SHA1)) {
      echo "Verify failed on signed data: $Data ";
  }
  </code></pre>