I am having severe difficulty getting PGP to work with my PHP script! I'm using popen() to create a pipe to PGP, and then using the same syntax that is successful on the command line.
<?
$pipe = popen("pgpe -r timothy -ao success", "w");
fwrite($pipe, "dummy text to be encrypted");
pclose($pipe);
?>
...where 'timothy' is a valid key id, and 'success' is my optimistic output filename. No 'success'. =(
What I really want to run is this code that I've seen in one form or another all around the web:
<?PHP
function pgp_encrypt($keyring_location, $public_key_id, $plain_text) {
$key_id = EscapeShellArg($public_key_id);
putenv("PGPPATH=$keyring_location");
// encrypt the message
$pipe = popen("pgpe -r $key_id -af", "r");
fwrite($pipe, $plain_text);
$encrypted_text = '';
while($s = fgets($pipe, 1024)) {
// read from the pipe
$encrypted_text .= $s;
}
pclose($pipe);
return $encrypted_text;
}
$message = pgp_encrypt("/usr/home/myaccnt/.pgp", "timothy", "dummy text to be encrypted");
print nl2br($message);
?>
I'm running on Solaris, and the hosting company claims that bidirectional pipes should work. All I get is a blank screen.
I'm really stuck! Please help.