openssl_pkcs7_encrypt
(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
openssl_pkcs7_encrypt — 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
이라는 파일의 내용을 가져와 RC2 40비트 암호를 사용하여 암호화하여 certificate
로 지정된 의도된 수신자만 읽을 수 있도록 합니다.
매개변수
input_filename
output_filename
certificate
- 단독 X.509 인증서 또는 X.509 인증서 array.
headers
headers
는 데이터가 암호화된 후 데이터 앞에 추가될 헤더 배열입니다.headers
는 헤더 이름으로 키가 지정된 연관 배열이거나 각 요소에 단일 헤더 행이 포함된 인덱스 배열일 수 있습니다.flags
flags
는 인코딩 프로세스에 영향을 미치는 옵션을 지정하는 데 사용할 수 있습니다. PKCS7 상수를 참조하십시오.cipher_algo
- cipher 상수 중 하나입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
8.1.0 | 기본 암호 알고리즘(cipher_algo )은 이제 AES-128-CBC(OPENSSL_CIPHER_AES_128_CBC )입니다. 이전에는 PKCS7/CMS를 사용했습니다(OPENSSL_CIPHER_RC2_40 ). |
8.0.0 | 이제 certificate 가 OpenSSLCertificate 인스턴스를 허용합니다. 이전에는 OpenSSL X.509 CSR 유형의 리소스가 허용되었습니다. |
Examples
예제 #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");
}
?>