note 103707 added to function.openssl-pkcs7-decrypt
| From: | oliver at anonsphere dot com | Date: | Fri, 29 Apr 2011 04:16:11 +0000 |
| Subject: | note 103707 added to function.openssl-pkcs7-decrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179257@lists.php.net to get a copy of this message | ||
If you want to decrypt a received email, keep in mind that you need the full encrypted message
including the mime header.
<?php
// Get the full message
$encrypted = imap_fetchmime($stream, $msg_number, "1", FT_UID);
$encrypted .= imap_fetchbody($stream, $msg_number, "1", FT_UID);
// Write the needed temporary files
$infile = tempnam("", "enc");
file_put_contents($infile, $encrypted);
$outfile = tempnam("", "dec");
// The certification stuff
$public = file_get_contents("/path/to/your/cert.pem");
$private = array(file_get_contents("/path/to/your/cert.pem"), "password");
// Ready? Go!
if(openssl_pkcs7_decrypt($infile, $outfile, $public, $private))
{
// Decryption successful
echo file_get_contents($outfile);
}
else
{
// Decryption failed
echo "Oh oh! Decryption failed!";
}
// Remove the temp files
@unlink($infile);
@unlink($outfile);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 77.9.68.176
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-decrypt.php
Edit -- https://master.php.net/note/edit/103707
Del: integrated -- https://master.php.net/note/delete/103707/integrated
Del: useless -- https://master.php.net/note/delete/103707/useless
Del: bad code -- https://master.php.net/note/delete/103707/bad+code
Del: spam -- https://master.php.net/note/delete/103707/spam
Del: non-english -- https://master.php.net/note/delete/103707/non-english
Del: in docs -- https://master.php.net/note/delete/103707/in+docs
Del: other reasons-- https://master.php.net/note/delete/103707
Reject -- https://master.php.net/note/reject/103707
Search -- https://master.php.net/manage/user-notes.php