Forum Moderators: coopster

Message Too Old, No Replies

gnupg encryption not working through php script

encryption through public key

         

dharmendu

3:04 pm on May 14, 2005 (gmt 0)

10+ Year Member



i have tried following code for encryption through gnupg but it is not working. i think some problem related with the path issue?
it works fine from shell and encrypt the file but not working through php file. Please help me.

code___-----------------------

<?
//build the message string
$msg = "Sender's Full Name:\t$sender_name\n";
$msg .= "Sender's E-Mail:\t$sender_email\n";
$msg .= "Secret Message?\t$secret_msg\n\n";
//set the environment variable for PGPPATH
putenv("GNUPGHOME=/home/user/.gnugp");

//generate token for unique filenames
$tmpToken = md5(uniqid(rand()));

//create vars to hold paths and filenames
$plainTxt = "/home/user/public_html/" . "$tmpToken" . "data";
$crypted = "/home/user/public_html/" . "$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/bin/gpg --encrypt -ao $crypted -r 'recipient' $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 = "julie@example.com";
$subject = "Secret Message";

$mailheaders = "From: My Web Site\n";
$mailheaders .= "Reply-To: $sender_email\n\n";

mail("$recipient", "$subject", $mail_cont, $mailheaders);

// Print confirmation to screen.
echo "
<H1 align=center>Thank You, $sender_name</h1>
<p align=center>Your secret message has been sent.</p>
";

?>

[edited by: jatar_k at 3:37 pm (utc) on May 14, 2005]
[edit reason] generalized url [/edit]

coopster

8:41 pm on May 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, dharmendu.

What's not working? The encryption? The mail confirmation? Are you receiving any error messages?

dharmendu

7:27 am on May 15, 2005 (gmt 0)

10+ Year Member



As i already mentioned in the subject line, gnupg encryption is not working through php script. Sending email is ok, i can manage that but this encryption is not working somehow.
Thanks