openssl_pkcs7_encrypt

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

openssl_pkcs7_encrypt锟斤拷锟斤拷一锟斤拷 S/MIME 锟斤拷息

说锟斤拷

openssl_pkcs7_encrypt ( string $infile , string $outfile , mixed $recipcerts , array $headers [, int $flags = 0 [, int $cipherid = OPENSSL_CIPHER_RC2_40 ]] ) : bool

openssl_pkcs7_encrypt() 锟斤拷取锟侥硷拷锟斤拷为infile锟斤拷锟侥硷拷锟斤拷锟捷诧拷使锟斤拷 RC2 40位锟斤拷锟斤拷锟诫将之锟斤拷锟杰o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷只锟杰憋拷预锟节碉拷锟斤拷为recipcerts锟侥斤拷锟斤拷锟斤拷锟侥讹拷锟斤拷

锟斤拷锟斤拷

infile

outfile

recipcerts

一锟斤拷锟斤拷锟斤拷锟斤拷X.509证锟介,锟斤拷锟斤拷一锟斤拷X.509证锟斤拷锟斤拷锟斤拷椤�

headers

headers 锟角帮拷锟斤拷头锟斤拷息锟斤拷锟斤拷锟介,锟节憋拷锟斤拷锟杰后将讹拷锟斤拷锟捷斤拷锟斤拷预锟斤拷锟斤拷

headers 锟斤拷锟斤拷锟斤拷锟斤拷头锟斤拷为锟斤拷值锟侥癸拷锟斤拷锟斤拷锟介,也锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟介,锟斤拷锟斤拷每锟斤拷元锟截讹拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟侥憋拷锟斤拷锟斤拷

flags

flags锟斤拷锟斤拷指锟斤拷影锟斤拷锟斤拷锟斤拷锟教碉拷选锟斤拷 - 锟轿硷拷 PKCS7 锟斤拷锟斤拷.

cipherid

锟斤拷锟诫常锟斤拷之一锟斤拷

锟斤拷锟斤拷值

锟缴癸拷时锟斤拷锟斤拷 TRUE锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

锟斤拷锟斤拷

Example #1 openssl_pkcs7_encrypt() 锟斤拷锟斤拷

<?php
// the message you want to encrypt and send to your secret agent
// in the field, known as nighthawk.  You have his certificate
// in the file nighthawk.pem
$data = <<<EOD
Nighthawk,

Top secret, for your eyes only!

The enemy is closing in! Meet me at the cafe at 8.30am
to collect your forged passport!

HQ
EOD;

// load key
$key file_get_contents("nighthawk.pem");

// save message to file
$fp fopen("msg.txt""w");
fwrite($fp$data);
fclose($fp);

// encrypt it
if (openssl_pkcs7_encrypt("msg.txt""enc.txt"$key,
    array(
"To" => "nighthawk@example.com"// keyed syntax
          
"From: HQ <hq@example.com>"// indexed syntax
          
"Subject" => "Eyes only"))) {
    
// message encrypted - send it!
    
exec(ini_get("sendmail_path") . " < enc.txt");
}
?>