PHP & GNUPG question...

bernardino lopez bernardino_lopez@yahoo.com
Thu Nov 1 19:06:01 2001


I wonder why PHP does not show the result of the
encryption.

Running in a RedHat 6.2 PHP, SSL, MySQL, Apache &&
Gnupg from the shell:
 
[gpg@prsvrlx7 html]$ ll
total 16
-rwxr-xr-x    1 gpg      gpg          1036 Oct 30
14:11 dino.php
-rw-rw-r--    1 gpg      gpg           454 Oct 30
14:36 dino2.php
-rwxr-xr-x    1 gpg      gpg           202 Oct 30
15:09 go.sh
-rw-rw-r--    1 gpg      gpg          1369 Oct 30
14:12 secret.asc

[gpg@prsvrlx7 html]$ pwd
/home/gpg/html

[gpg@prsvrlx7 html]$ cat go.sh
echo "Text that will be encrypted" |
/usr/local/bin/gpg -a --always-trust --batch
--no-secmem-warning -e -u "Bernardino Lopez
<blopez@progressrail.com>" -r "Bernardino Lopez
<blopez@progressrail.com>";

[gpg@prsvrlx7 html]$ ./go.sh
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
 
hQEOA4gYLa4BqW43EAP+KOTJ4Evdo+FoWmQmi/DxO4mUeAXSPZn4iGQ7RqMplRvX
2CDpLlYTTTH5EvFqaMNk3xQG4LgTwKM+0cOHXufdhI4iu3G1bkA5eu8+Ic0Jh0le
+grhDSOMN2ylN1pvgYN6yX02YDq5RiQEVdsLKfEJ5RZC6YaDHGD1XuMG1HGuWe8D
/0ZS2JEzuhCpTOqC6Zg0lKd7OJDcRSLw3s5efUI0qE2vWyrDz9g+cr0xzyUiKt1r
ndXjD8+vWjR1rhhfHEoHn8tqdMc3GDUD1Wz3AhpVggKi2nuOPl8/U5OoRnHxkNBu
wRNV6dq7Rh6ZwzBrDYB4CZlKvlFs3SyFal3tjUiVTeAd0lcBxJIjT88BxmAswas3
4Fm1ySO98/yJ8eZPUZhsPxHBcdTN0guhBe/x25df3x4GAopZhFFSXU3fU1bBOXDM
Zp/1LZzcGB0mv1KQY33Rba12rxSUwB2Jovw=
=qPUC
-----END PGP MESSAGE-----
[gpg@prsvrlx7 html]$

Or just typing echo from the shell:
 
[gpg@prsvrlx7 html]$ echo "Text that will be
encrypted" | /usr/local/bin/gpg -a --always-trust
--batch --no-secmem-warning -e -u "Bernardino Lopez
<blopez@progressrail.com>" -r "Bernardino Lopez
<blopez@progressrail.com>";
bash: cho: command not found
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
 
hQEOA4gYLa4BqW43EAP/arvLjKrfu8M6eNb7RCgQzxnkmACoyv74so77yg8YQo5i
bNySD6uw/QFX7Inh3MbPddWRnVsFEz1ZxQt/Cv0aKtqnPQSAsdNKX270SLEJ1QKE
jSmyz1tjxtehIIHq+wdzZs/5HUA2LcWTusAwERl1STZ37VvFs5ywReOQvendQBUD
/0RIJzZbkTQV6uiemnE1Py2rkx6EHx57l3J0jFDqX9c7erl33jnjie75/q8anszL
dTwyFj6ndOJg6fmUvSR3zoBUHyVOKMbS3iRh4jW5bwhaFvjzsLS01sP9B2Hm4uvX
ZoFI6KTv0do+TnakPd/dIpD8SQKf+/sRce4IqEUBbHwf0jsB9pUSjqyMZdH1jRhD
SPw9AQSzeVTDwg8DGeLM1C+4CTW0OLrDO35l4u0XapXB8eUtGirksUXUodX8tg==
=1xyv
-----END PGP MESSAGE-----
[gpg@prsvrlx7 html]$

Now when I run the PHP program:
 
 
<?
//Set the username to the user on the server
$username = "dummy";
 
$pgp="/usr/local/bin/gpg";
 
// User that is sending the e-mail (In the from
address etc..)
$user="Bernardino Lopez <blopez@progressrail.com>";
 
//This is the key that was uploaded, i.e. the recipent
of the PGP message
$recp="Bernardino Lopez <blopez@progressrail.com>";
 
$data="Text that will be encrypted";
 

$command = "Text that will be encrypted\" |
/usr/local/bin/gpg -a --always-trust --batch
--no-secmem-warning -e -u \"Bernardino Lopez
<blopez@progressrail.com>\" -r \"Bernardino Lopez
<blopez@progressrail.com>";
 
#$command = "$pgp --help";
#$command = "$pgp --version";
 

$command=htmlspecialchars($command);
echo "$command <br>";
$oldhome = getEnv("HOME");
 
putenv("HOME=/home/$username");
$result = exec($command, $encrypted, $errorcode);
putenv("HOME=$oldhome");
 
$message = implode("\n", $encrypted);
if(ereg("-----BEGIN PGP MESSAGE-----.*-----END PGP
MESSAGE-----",$message))
{
        echo "It Worked";
}else
{
        echo "It failed";
}
$subject="Test message";
$header="From: $user";
 
echo "Message<br>";
echo nl2br($message);
 
#mail($recp,$subject,$message,$header);
?>

 
The $command for 
#$command = "$pgp --help";
#$command = "$pgp --version";
They work ok, but I never can get the Encrypted
message.
 
Some Suggestion???
 
 
Regards Din00z.
www.edomex.net/phpopenmonitor/
Brains R like books only work when they r open.
 
 
 


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com