title: Can't decrypt signed S/Mime Message
body: <p>I'm at the moment realizing an S/Mime decryption using PHP. What i got so far:</p>
  
  <pre><code>    $keys = array("public"=&gt;$atm."/public-keys/".$usr.".smime",
          "private"=&gt;$atm."/private-keys/".$usr.".smime");
      if(!file_exists($keys["public"])) die("Public Key not found");
      if(!file_exists($keys["private"])) die("Private Key not found");
      $public = file_get_contents($keys["public"]);
      $private = file_get_contents($keys["private"]);
  
      switch($_GET["debug"])
      {
          case "encrypt":
          {
              $outfile = realpath("demo-msg/out.txt");
              $outfile_signed = realpath("demo-msg/out.signed.txt");
              $infile = realpath("demo-msg/in.txt");
  
              file_put_contents($infile,$msg);
              $adddata = array("To" =&gt; "XXX", "From: Demo Name &lt;XXX&gt;", "Subject" =&gt; "Demo Subject");
              if (openssl_pkcs7_encrypt($infile, $outfile, $public, $adddata))
              {
                  //$info = file_get_contents($outfile);
                  echo "winenc &amp; transfer&lt;br&gt;\n";
                  file_put_contents($infile, file_get_contents($outfile));
                  //if(openssl_pkcs7_sign($outfile,$outfile_signed,$public,$private,$adddata, PKCS7_BINARY)) echo "winsign";
                  //else echo "failsign";
              } 
              else echo "Failed Encryption";
              exit;
          }
          default:
          {
              $outfile2 = realpath("demo-msg/out2.txt");
              $outfile = realpath("demo-msg/out.txt");
              $infile = realpath("demo-msg/smime.p7m");
              //$infile = realpath("demo-msg/in.txt");
  
              if(openssl_pkcs7_verify($infile)) echo "verified&lt;br&gt;\n"; //tried: openssl_pkcs7_verify($infile,$PKCS7_DETACHED, tmpfile(), array(), array(), $outfile)
              else die("invalid sig");
  
              if(openssl_pkcs7_decrypt($infile, $outfile2, $public, $private)) //tried: openssl_pkcs7_decrypt($outfile, $outfile2, $public, $private)
              {
                  echo "dec win:".file_get_contents($outfile2);
              }
              else echo "Oh oh! Decryption failed!";
              exit;
          }
      }
  </code></pre>
  
  <p>What this snippet already <strong>can</strong> do:</p>
  
  <ul>
  <li>Encrypt a Message</li>
  <li>Decrypt an encrypted message (created by itself)</li>
  <li>Decrypt an encrypted message (Office 2010) as long as it's not signed</li>
  </ul>
  
  <p>Now, i want to decrypt messages that are signed too (as it's usually one step). The Problem: </p>
  
  <ul>
  <li>If i first try a decrypt, it'll return the encrypted message with different headers. Multiple decryptions lead to the same result.</li>
  <li>My thought was using the $content - parameter of the verification - command (openssl_pkcs7_verify). You can see my attempt in the code-comments. </li>
  </ul>
  
  <p>Nevertheless, i don't have any clues what can be wrong with the second attempt. ANy help would be appreciated!</p>