W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
openssl_pkcs7_encrypt — 加密一個(gè) S/MIME 消息
openssl_pkcs7_encrypt(
string $input_filename,
string $output_filename,
OpenSSLCertificate|array|string $certificate,
?array $headers,
int $flags = 0,
int $cipher_algo = OPENSSL_CIPHER_AES_128_CBC
): bool
openssl_pkcs7_encrypt() 獲取名為 input_filename 的文件內(nèi)容并使用 RC2 40 位的密碼將之加密,以至于他們只能被預(yù)期的名為 certificate 的接收者閱讀。
input_filename
output_filename
certificate
一個(gè)單獨(dú)的X.509證書(shū),或者一個(gè)X.509證書(shū)的數(shù)組。
headers
headers
是包含頭信息的數(shù)組,在被加密后將對(duì)數(shù)據(jù)進(jìn)行預(yù)處理。
headers
可以是以頭名為鍵值的關(guān)聯(lián)數(shù)組,也可以是一個(gè)索引數(shù)組,其中每個(gè)元素都包含一個(gè)單獨(dú)的標(biāo)題行
flags
flags
用來(lái)指定影響編碼過(guò)程的選項(xiàng) - 參見(jiàn) PKCS7 常量.
cipcipher_algoherid
密碼常量之一。
成功時(shí)返回 true, 或者在失敗時(shí)返回 false。
版本 | 說(shuō)明 |
---|---|
8.1.0 | 默認(rèn)密碼算法(cipher_algo )現(xiàn)在是 AES-128-CBC(OPENSSL_CIPHER_AES_128_CBC )。以前,使用 PKCS7/CMS (OPENSSL_CIPHER_RC2_40 )。 |
8.0.0 | certificate 現(xiàn)在接受 OpenSSLCertificate 實(shí)例;之前接受類型 OpenSSL X.509 CSR 的 resource。 |
示例 #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");
}
?>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: