<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.openssl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.openssl-pkcs7-sign.php',
    1 => 'openssl_pkcs7_sign',
    2 => 'Signe un message S/MIME',
  ),
  'up' => 
  array (
    0 => 'ref.openssl.php',
    1 => 'Fonctions OpenSSL',
  ),
  'prev' => 
  array (
    0 => 'function.openssl-pkcs7-read.php',
    1 => 'openssl_pkcs7_read',
  ),
  'next' => 
  array (
    0 => 'function.openssl-pkcs7-verify.php',
    1 => 'openssl_pkcs7_verify',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/openssl/functions/openssl-pkcs7-sign.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.openssl-pkcs7-sign" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_pkcs7_sign</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_pkcs7_sign</span> &mdash; <span class="dc-title">Signe un message S/MIME</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-pkcs7-sign-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_pkcs7_sign</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$input_filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$output_filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$certificate</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><span class="type"><a href="class.opensslasymmetrickey.php" class="type OpenSSLAsymmetricKey">OpenSSLAsymmetricKey</a></span>|<span class="type"><a href="class.opensslcertificate.php" class="type OpenSSLCertificate">OpenSSLCertificate</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$private_key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$headers</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="openssl.pkcs7.flags.php#constant.pkcs7-detached">PKCS7_DETACHED</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$untrusted_certificates_filename</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_pkcs7_sign()</strong></span> prend le contenu du fichier
   <code class="parameter">input_filename</code> et le signe en utilisant le
   certificat et la clé privée contenus dans les arguments
   <code class="parameter">certificate</code> et <code class="parameter">private_key</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-pkcs7-sign-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">input_filename</code></dt>
     <dd>
      <p class="para">
       Le fichier d&#039;entrée qu&#039;on a l&#039;intention de signer numériquement.
      </p>
     </dd>
    
    
     <dt><code class="parameter">output_filename</code></dt>
     <dd>
      <p class="para">
       Le fichier où la signature numérique sera écrite.
      </p>
     </dd>
    
    
     <dt><code class="parameter">certificate</code></dt>
     <dd>
      <p class="para">
       Le certificat X.509 utilisé pour signer numériquement <code class="parameter">input_filename</code>.
       Voir <a href="openssl.certparams.php" class="link">paramètres Clé/Certificat</a>
       pour une liste de valeurs valides.
      </p>
     </dd>
    
    
     <dt><code class="parameter">private_key</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">private_key</code> est la clé privée correspondant à <code class="parameter">certificate</code>.
       Voir <a href="openssl.certparams.php" class="link">paramètres Clé Publique/Privée</a>
       pour une liste de valeurs valides.
      </p>
     </dd>
    
    
     <dt><code class="parameter">headers</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">headers</code> est un tableau d&#039;en-têtes qui
       seront ajoutés aux données chiffrées (voir la fonction
       <span class="function"><a href="function.openssl-pkcs7-encrypt.php" class="function">openssl_pkcs7_encrypt()</a></span> pour plus de détails sur
       le format du paramètre).
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">flags</code> peut être utilisé pour modifier la sortie.
       Voir les <a href="openssl.pkcs7.flags.php" class="link">constantes PKCS7</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">untrusted_certificates_filename</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">untrusted_certificates_filename</code> spécifie le nom du fichier contenant
       un ensemble de certificats supplémentaires à inclure dans la
       signature, qui pourront aider le destinataire à vérifier les
       données qu&#039;on utilise.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-pkcs7-sign-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Cette fonction retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.openssl-pkcs7-sign-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">certificate</code> accepte désormais une instance de
       <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> ;
       auparavant, une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de type <code class="literal">OpenSSL X.509 CSR</code> était acceptée.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">private_key</code> accepte désormais une instance de
       <span class="classname"><a href="class.opensslasymmetrickey.php" class="classname">OpenSSLAsymmetricKey</a></span> ou <span class="classname"><a href="class.opensslcertificate.php" class="classname">OpenSSLCertificate</a></span> ;
       auparavant, une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de type <code class="literal">OpenSSL key</code> ou <code class="literal">OpenSSL X.509</code>
       était acceptée.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-pkcs7-sign-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>openssl_pkcs7_sign()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// le message que vous voulez signer, afin que le destinataire soit sûr qu'il<br />// vient bien de vous<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= &lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000"><br />Vous êtes autorisé à dépenser 10 000€ en note de frais.<br /><br />Le PDG<br /></span><span style="color: #007700">EOD;<br /></span><span style="color: #FF8000">// sauvez le message dans un fichier<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"msg.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// encrypt it<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">openssl_pkcs7_sign</span><span style="color: #007700">(</span><span style="color: #DD0000">"msg.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"signed.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"file://mycert.pem"</span><span style="color: #007700">,<br />    array(</span><span style="color: #DD0000">"file://mycert.pem"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mypassphrase"</span><span style="color: #007700">),<br />    array(</span><span style="color: #DD0000">"To" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"joes@example.com"</span><span style="color: #007700">, </span><span style="color: #FF8000">// syntaxe à clé<br />          </span><span style="color: #DD0000">"From: HQ &lt;ceo@example.com&gt;"</span><span style="color: #007700">, </span><span style="color: #FF8000">// syntaxe indexée<br />          </span><span style="color: #DD0000">"Subject" </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"Eyes only"</span><span style="color: #007700">)<br />    )) {<br />    </span><span style="color: #FF8000">// message signée - envoyez-le !<br />    </span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">"sendmail_path"</span><span style="color: #007700">) . </span><span style="color: #DD0000">" &lt; signed.txt"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>