I need to encrypt a file with PGP, but I am lost. I am trying to follow this script: http://www.alt-php-faq.org/local/65/
My scenario is a little different that this snippt is using. I have the public of key for the person that will ultimately recieve the file. I don't care about creating or using a key pair for myself, just encrypting this file before it is sent off. I have this file uploaded to the server, as well as file that needs to be encrypted. How can I modify this script to do what I need?
Also, the script refers the pgp location on the server as "/usr/local/bin/gpg". I don't have that, so I did a locate, and got a ton of results. I am posting the most relevant ones (I think) below. Which one should I use for the pgp location?
/usr/bin/lspgpot
/usr/bin/pgpewrap
/usr/bin/pgpring
/home/username/public_html/.pgp
Thanks to whoever keeps me from bleeding out my ears.
Here is the script itself:
<?php
//Set the username to the user on the server
$username = "thepurpl";
$pgp="/usr/local/bin/gpg";
// User that is sending the e-mail (In the from address etc..)
$user="Darren Casey <updates@alt-php-faq.org>";
//This is the key that was uploaded, i.e. the recipent of the PGP message
$recp="First Last <user@domain.com>";
$data="Text that will be encrypted";
$command = 'echo "'.$data.'" | '.$pgp.' -a --always-trust --batch --no-secmem-warning -e -u "'.$user.'" -r "'.$recp.'"';
$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);
?>