I should say, my host uses a modified form of safe mode, so I don't know if that might have caused a problem with "popen" as opposed to "proc_open". With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". [Because of this,] LinixDude010's srcipt did not work for me. Seems wrong to read and write with popen, according to the manual.
The script produced pgp text, but there was something wrong with the text and I could not decode it.
This replacement script, using proc_open, which can read and write, DOES work:
<?php
function pgp_encrypt($keyring_location, $public_key_id, $plain_text) {
$encrypted_text='';
$key_id = EscapeShellArg($public_key_id);
putenv("PGPPATH=$keyring_location");
$descriptorspec = array(
0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") );
$process = proc_open("pgpe -r $key_id -af", $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $plain_text);
fclose($pipes[0]);
while($s= fgets($pipes[1], 1024)) {
$encrypted_text .= $s;
}
fclose($pipes[1]);
while($s= fgets($pipes[2], 1024)) {
$encrypted_text.= "\n<p>Error: $s</p>\n";
}
fclose($pipes[2]);
}
return $encrypted_text;
}
$message = pgp_encrypt("/home/username/.pgp", "to@domain.com", "dummy text to be encrypted");
print nl2br($message);
?>