Page 1 of 1

GPG + PHP + proc_open

Posted: Fri Oct 29, 2004 5:45 am
by mchaggis
Hi,

I amm writing a class to act as a wrapper for gpg, this I have managed to do successfully, but now I am looking to implement the sign_key function. Only problem is it behaves completely different to how I expect.

I have read that you can use proc_open for gpg, but am unclear how I would go about actually passing all the answers to the various questions that gpg asks you prior to signing.

Any help??

The code I have so far is:

Code: Select all

<?php
$descriptor = Array(
            0 => array("pipe", "r"), # STDIN
            1 => array("pipe", "w"), # STDOUT
            2 => array("file", "/tmp/errors","a"), # STDERR
);
$process = proc_open($this->GPGBIN." --no-secmem --no-secmem-warning --always-trust -q --sign-key $key",$descriptor, $pipes);
if (is_resource($process)) {
         fwrite($pipes[0], "2\n");
         fwrite($pipes[0], "y\n");
         fwrite($pipes[0], "$passphrase\n");
         fclose($process);
         proc_close($process);
} else {
         print "Darn it!";
}

?>