note 107892 added to function.openssl-pkcs7-encrypt
| From: | Anonymous | Date: | Tue, 13 Mar 2012 14:37:58 +0000 |
| Subject: | note 107892 added to function.openssl-pkcs7-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186629@lists.php.net to get a copy of this message | ||
To build on what people have already done, below is a function that takes a from address, an array
of e-mails/public keys, a subject, and a message and sends out an encrypted message using the
appropriate public key.
Since we're sending an encrypted message, the assumption is that what we're sending is
actually critical. As a result the files used for sending the message are immediately shredded.
$recipients = Array("user@example.com"=>file_get_contents("cert.pem"));
$body = 'secret text';
sendSignedMail("me@examplel.com", $recipients, "Test Message", $body);
//Recepients is an array of e-mail address=>Key
function sendSignedMail($from, $recepients, $subject, $body){
foreach($recepients AS $email=>$key){
$tfn_in = tempnam("/tmp", "b");
$tfn_out = tempnam("/tmp", "e");
$handle = fopen($tfn_in, "w");
fwrite($handle, $body);
fclose($handle);
openssl_pkcs7_encrypt($tfn_in, $tfn_out, $key,
array("To" => $email,
"From" => $from,
"Subject" => $subject), 0);
$data = file_get_contents($tfn_out);
//Shred the files since this is sensitive data.
$handle = popen("/usr/bin/shred -n 3 -u $tfn_in", 'r');
pclose($handle);
$handle = popen("/usr/bin/shred -n 3 -u $tfn_out", 'r');
pclose($handle);
$parts = explode("\n\n", $data, 2);//Fixes headers in mail function
mail($email, $subject, $parts[1], $parts[0]);
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 64.94.76.45
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-encrypt.php
Edit -- https://master.php.net/note/edit/107892
Del: integrated -- https://master.php.net/note/delete/107892/integrated
Del: useless -- https://master.php.net/note/delete/107892/useless
Del: bad code -- https://master.php.net/note/delete/107892/bad+code
Del: spam -- https://master.php.net/note/delete/107892/spam
Del: non-english -- https://master.php.net/note/delete/107892/non-english
Del: in docs -- https://master.php.net/note/delete/107892/in+docs
Del: other reasons-- https://master.php.net/note/delete/107892
Reject -- https://master.php.net/note/reject/107892
Search -- https://master.php.net/manage/user-notes.php