note 21030 modified in function.openssl-pkcs7-encrypt by vrana

From: Date: Wed, 10 Mar 2004 06:51:22 +0000
Subject: note 21030 modified in function.openssl-pkcs7-encrypt by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66527@lists.php.net to get a copy of this message
The example code is wrong (at least as of 4.2.0). The recipcerts parameter is either the actual text of the base64 encoded key file, or it must be a filename in "file://..." format. A normal path will not work (OpenSSL tries to use the path as the actual certificate). The above code works as: <?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 = implode("", file("my.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" => "example@example.com", // keyed syntax "From: HQ <hq@cia.com>", // indexed syntax "Subject" => "Eyes only"))) { // message encrypted - send it! exec(ini_get("sendmail_path") . " < enc.txt"); } ?> [You can also pass an array of recipcerts values, but I haven't used that so I don't know what it's expecting.] --was-- The example code is wrong (at least as of 4.2.0). The recipcerts parameter is either the actual text of the base64 encoded key file, or it must be a filename in "file://..." format. A normal path will not work (OpenSSL tries to use the path as the actual certificate). The above code works as: // 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 = implode("", file("my.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" => "msisolak@gvpi.com", // keyed syntax "From: HQ <hq@cia.com>", // indexed syntax "Subject" => "Eyes only"))) { // message encrypted - send it! exec(ini_get("sendmail_path") . " < enc.txt"); } [You can also pass an array of recipcerts values, but I haven't used that so I don't know what it's expecting.] http://www.php.net/manual/en/function.openssl-pkcs7-encrypt.php

« previous php.notes (#66527) next »