GnuPG and PHP
Julien M.
blob@oxyd.fr
Wed Dec 26 15:20:02 2001
Hi,
I'm using a php script to sign mail with GPG.
I succeed in sending an encrypted mail, but no way to send a -only- signed
mail...
( it works when i do it directly on the computer ).
I need your help...
(PHP execute gpg --encrypt.. but not working for --sign or --clearsign ).
Thx.
The script:
<?
//build the message string
$msg = "$secret_msg";
//set the environment variable for PGPPATH
putenv("GNUPGHOME=/datas/home/blob/.gnupg");
//generate token for unique filenames
$tmpToken = md5(uniqid(rand()));
//create vars to hold paths and filenames
$plainTxt = "/www/pgp/tmp/" . "$tmpToken" . "data";
$crypted = "/www/pgp/tmp/" . "$tmpToken" . "pgpdata";
//open file and dump in plaintext contents
$fp = fopen($plainTxt, "w+");
fputs($fp, $msg);
fclose($fp);
//invoke PGP to encrypt file contents
system("/usr/local/bin/gpg --encrypt -ao $crypted -r 'user user@isp.com'
$plainTxt");
//open file and read encrypted contents into var
$fd = fopen($crypted, "r");
$mail_cont = fread($fd, filesize($crypted));
fclose($fd);
//delete files!
unlink($plainTxt);
unlink($crypted);
// Build mail message and send it to target recipient.
$recipient = "user@isp.com";
$from_email = u@isp.com;
$entetedate = date("D, j M Y H:i:s -0600");
$entetemail = "From: $from_email \n";
$entetemail .= "Reply-To: $from_email \n";
$entetemail .= "Date: $entetedate";
$entetemail .= "Content-Type: text/plain; charset=\"US-ASCII\"\n";
$entetemail .= "Content-Transfer-Encoding: 7bit";
mail("$recipient", "", $mail_cont, $entetemail);
// Print confirmation to screen.
echo "
<H1 align=center>Thank You, $sender_name</h1>
<p align=center>Your secret message has been sent.</p>
";
?>