Re: proc_open to return an encrypted string?

From: Date: Mon, 06 Oct 2003 18:54:47 +0000
Subject: Re: proc_open to return an encrypted string?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165229@lists.php.net to get a copy of this message
* Thus wrote Robert Van Overmeiren (vanoverr@uniteddrugs.com): > Hello, > > I want to take a String variable and GPG encrypt it, then email the > encrypted string. > > One of our developers suggested using "proc_open" and to "set the process to > 'gpg -a --encrypt -r 0x35E891B0'", but couldn't clarify. > > How is this done? Would it be something like this...? I'm not familiar with proc_open being that it is knew but yes the idea is correct. > ----------------------------------------- > > $message = "Text or HTML string"; > > $pipes = "-a --encrypt -r 0x35E891B0"; The $pipes parameter isn't the arguments to the script but an array that is returned with the pipe you defiend below. > > $descriptorspec = array(0 => array("pipe", "r"), 1 => > array("pipe", "w"), 2 > => array("file", "/tmp/error-output.txt", "a")); In most cases you may want your #2 stream (the error stream) to go to a pipe back to this script. so you want 2=> array('pipe', 'r') > > $process = proc_open("gpg", $descriptorspec, $pipes); Pass your parameters like so: $process = proc_open("gpg -a --encrypt ...", $descriptorspec, $pipes); > > if (is_resource($process)) { > fwrite($pipes[0], $message); > fclose($pipes[0]); Now you can check the error stream and do some error checking: while(!feof($pipes[2])) { $errors .= fgets($pipes[2], 1024); } fclose($pipes[2]); //... error checking stuff. > while(!feof($pipes[1])) { > echo fgets($pipes[1], 1024); > } > fclose($pipes[1]); > $return_value = proc_close($process); > } > > send_mail($smtp_server, $smtp_port, $sender_email, $recipient_email, > $subject, $message, $headers); > I believe you need to set some headers to tell the email program that this message is encrypted, but I might be wrong. Curt -- List Stats: http://zirzow.dyndns.org/html/mlists/php_general/ "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#165229) next »