note 13952 deleted from function.popen by didou

From: Date: Thu, 19 Feb 2004 17:29:47 +0000
Subject: note 13952 deleted from function.popen by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65411@lists.php.net to get a copy of this message
Note Submitter: sasam@datagate.co.uk ---- I found that PHP4.0.4pl1 on Redhat 6.2 does not allow 'w+' flag in popen() to create a bi-directional pipe. Just use plain 'r' instead! Here is a simple function using popen() to encrypt plain text with PGP public key encryption. Bi-directional pipes are quite usabe here - no temporary files will be created on the disc. This function was successfully tested on Redhat 6.2 with PHP 4.0.4pl1 and PGP 6.5.8 (note: the encryption key must be signed to avoid any PGP warnings). function pgp_encrypt($keyring_location, $public_key_id, $plain_text) { $key_id = EscapeShellArg($public_key_id); putenv("PGPPATH=$keyring_location"); // NOTE 'r' in the following popen() call $pipe = popen("pgp -feat +force $key_id" , 'r'); // write to the pipe fwrite($pipe, $plain_text); $encrypted_text = ''; while($s = fgets($pipe, 1024)) { // read from the pipe $encrypted_text .= $s; }; pclose($pipe); return $encrypted_text; } $encrypted_text = pgp_encrypt( "/home/sasam/.pgp", // folder with your keyrings "Sasa D. Markovic <sasam@net.yu>", // public key id "First line\nSecond line" // text to be encrypted );

« previous php.notes (#65411) next »