(PHP 4 >= 4.0.6, PHP 5, PHP 7)
openssl_pkcs7_encrypt — ����һ�� S/MIME ��Ϣ
$infile
, string $outfile
, mixed $recipcerts
, array $headers
[, int $flags
= 0
[, int $cipherid
= OPENSSL_CIPHER_RC2_40
]] ) : bool
openssl_pkcs7_encrypt() ��ȡ�ļ���Ϊinfile
���ļ����ݲ�ʹ�� RC2 40λ�����뽫֮���ܣ�����������ֻ�ܱ�Ԥ�ڵ���Ϊ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");
}
?>