note 49892 added to function.openssl-pkcs7-sign

From: Date: Fri, 11 Feb 2005 10:24:10 +0000
Subject: note 49892 added to function.openssl-pkcs7-sign
Groups: php.notes 
Request: Send a blank email to php-notes+get-84848@lists.php.net to get a copy of this message
It is also possible to sign message including attachments. An easy way to do this: <? $boundary = md5(uniqid(time())); $boddy = "MIME-Version: 1.0\n"; $boddy .= "Content-Type: multipart/mixed; boundary=\"" . $boundary. "\"\n"; $boddy .= "Content-Transfer-Encoding: quoted-printable\n\n"; $boddy .= "This is a multi-part message in MIME format.\n\n"; $boddy .= "--$boundary\n"; $boddy .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $boddy .= "Content-Transfer-Encoding: quoted-printable\n\n"; $boddy .= $EmailText . "\n\n"; // Add the attachment to the message do { $boddy .= "--$boundary\n"; $boddy .= "Content-Type: application/pdf; name=\"FileName\"\n"; $boddy .= "Content-Transfer-Encoding: base64\n"; $boddy .= "Content-Disposition: attachment;\n\n"; $boddy .= chunk_split(base64_encode($file)) . "\n\n"; } while ( {files left to be attached} ); $boddy .= "--$boundary--\n"; // Save message to a file $msg = 'msg.txt'; $signed = 'signed.txt'; $fp = fopen($msg, "w"); fwrite($fp, $boddy); fclose($fp); // Sign it if (openssl_pkcs7_sign($msg, $signed, 'file://cert.pem', array('file://key.pem', 'test'), array("To" => "joes@example.com", // keyed syntax "From: HQ <ceo@example.com>", // indexed syntax "Subject" => "Eyes only"), PKCS7_DETACHED, 'intermediate_cert.pem' )) { exec(ini_get('sendmail_path') . ' < ' . $signed); } ?> The same can be established by using the PEAR package Mail_Mime in combination with openssl_pkcs7_sign. ---- Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-sign.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49892 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49892&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49892&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49892&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49892&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49892&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49892&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84848) next »