Rechercher une fonction PHP

openssl_pkcs7_sign

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

openssl_pkcs7_signSign an S/MIME message

Description

openssl_pkcs7_sign ( string $infilename , string $outfilename , mixed $signcert , mixed $privkey , array $headers [, int $flags = PKCS7_DETACHED [, string $extracerts ]] ) : bool

openssl_pkcs7_sign() takes the contents of the file named infilename and signs them using the certificate and its matching private key specified by signcert and privkey parameters.

PHP: openssl_pkcs7_sign - Manual Home of Manuel PHP  Contents Haut

Parameters

infilename

The input file you are intending to digitally sign.

outfilename

The file which the digital signature will be written to.

signcert

The X.509 certificate used to digitally sign infilename. See Key/Certificate parameters for a list of valid values.

privkey

privkey is the private key corresponding to signcert. See Public/Private Key parameters for a list of valid values.

headers

headers is an array of headers that will be prepended to the data after it has been signed (see openssl_pkcs7_encrypt() for more information about the format of this parameter).

flags

flags can be used to alter the output - see PKCS7 constants.

extracerts

extracerts specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.

PHP: openssl_pkcs7_sign - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns TRUE on success or FALSE on failure.

PHP: openssl_pkcs7_sign - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 openssl_pkcs7_sign() example

<?php
// the message you want to sign so that recipient can be sure it was you that
// sent it
$data = <<<EOD

You have my authorization to spend $10,000 on dinner expenses.

The CEO
EOD;
// save message to file
$fp fopen("msg.txt""w");
fwrite($fp$data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_sign("msg.txt""signed.txt""file://mycert.pem",
    array(
"file://mycert.pem""mypassphrase"),
    array(
"To" => "joes@example.com"// keyed syntax
          
"From: HQ <ceo@example.com>"// indexed syntax
          
"Subject" => "Eyes only")
    )) {
    
// message signed - send it!
    
exec(ini_get("sendmail_path") . " < signed.txt");
}
?>

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-openssl-pkcs7-sign.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut