Hi,
I've written something that takes text and passes it to gpg to encrypt.
It works great except when the text size is greater than 64k at which
point PHP/Apache hangs. Is there any way around this? Below is a code
snippet (which may or may not help).
Thanks,
-r
function encryptContent( $fileContent, $encryptionKey)
{
if(!$this->gpgVerify())
{
$this->displayTextInT able('gpgVerify failed!');
exit;
}
$command = '/safeModeExecDir/gpg --homedir /data/.gnupg --armor
--cipher-algo AES256 --passphrase-fd 3 --batch
--no-tty --yes -c';
// set up pipes for handling I/O to/from GnuPG
// 0 === STDIN, a pipe that GnuPG will read the content from
// 1 === STDOUT, a pipe that GnuPG will write the encrypted
content to
// 2 === STDERR, a pipe that GnuPG will write to
// 3 === STDIN, a pipe that GnuPG will read the passphrase from
$descriptorSpec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
3 => array("pipe", "r")
);
$gpgProcess = proc_open($comm and, $descriptorSpec , $gpgPipes);
if(is_resource( $gpgProcess))
{
// this writes $fileContent to GnuPG on STDIN
if(false === fwrite($gpgPipe s[0], $fileContent,
strlen($fileCon tent)))
{
$this->displayTextInT able('fwrite failed!');
exit;
}
fclose($gpgPipe s[0]);
// this writes the $encryptionKey to GnuPG on fd 3
fwrite($gpgPipe s[3], $encryptionKey) ;
fclose($gpgPipe s[3]);
// this reads the encrypted output from GnuPG from STDOUT
$encryptedConte nt = '';
while(!feof($gp gPipes[1]))
{
$encryptedConte nt .= fgets($gpgPipes[1], 1024);
}
fclose($gpgPipe s[1]);
// this reads warnings and notices from GnuPG from STDERR
$gpgErrorMessag e = '';
while(!feof($gp gPipes[2]))
{
$gpgErrorMessag e .= fgets($gpgPipes[2], 1024);
}
fclose($gpgPipe s[2]);
// this collects the exit status of GnuPG
$processExitSta tus = proc_close($gpg Process);
// unset variables that are no longer needed
// and can only cause trouble
unset(
$fileContent,
$encryptionKey,
$command,
$descriptorSpec ,
$gpgProcess,
$gpgPipes,
$gpgErrorMessag e,
$gpgExitStatus
);
}
else
{
$this->displayTextInT able('proc_open () failed.');
exit;
}
return $encryptedConte nt;
}
I've written something that takes text and passes it to gpg to encrypt.
It works great except when the text size is greater than 64k at which
point PHP/Apache hangs. Is there any way around this? Below is a code
snippet (which may or may not help).
Thanks,
-r
function encryptContent( $fileContent, $encryptionKey)
{
if(!$this->gpgVerify())
{
$this->displayTextInT able('gpgVerify failed!');
exit;
}
$command = '/safeModeExecDir/gpg --homedir /data/.gnupg --armor
--cipher-algo AES256 --passphrase-fd 3 --batch
--no-tty --yes -c';
// set up pipes for handling I/O to/from GnuPG
// 0 === STDIN, a pipe that GnuPG will read the content from
// 1 === STDOUT, a pipe that GnuPG will write the encrypted
content to
// 2 === STDERR, a pipe that GnuPG will write to
// 3 === STDIN, a pipe that GnuPG will read the passphrase from
$descriptorSpec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
3 => array("pipe", "r")
);
$gpgProcess = proc_open($comm and, $descriptorSpec , $gpgPipes);
if(is_resource( $gpgProcess))
{
// this writes $fileContent to GnuPG on STDIN
if(false === fwrite($gpgPipe s[0], $fileContent,
strlen($fileCon tent)))
{
$this->displayTextInT able('fwrite failed!');
exit;
}
fclose($gpgPipe s[0]);
// this writes the $encryptionKey to GnuPG on fd 3
fwrite($gpgPipe s[3], $encryptionKey) ;
fclose($gpgPipe s[3]);
// this reads the encrypted output from GnuPG from STDOUT
$encryptedConte nt = '';
while(!feof($gp gPipes[1]))
{
$encryptedConte nt .= fgets($gpgPipes[1], 1024);
}
fclose($gpgPipe s[1]);
// this reads warnings and notices from GnuPG from STDERR
$gpgErrorMessag e = '';
while(!feof($gp gPipes[2]))
{
$gpgErrorMessag e .= fgets($gpgPipes[2], 1024);
}
fclose($gpgPipe s[2]);
// this collects the exit status of GnuPG
$processExitSta tus = proc_close($gpg Process);
// unset variables that are no longer needed
// and can only cause trouble
unset(
$fileContent,
$encryptionKey,
$command,
$descriptorSpec ,
$gpgProcess,
$gpgPipes,
$gpgErrorMessag e,
$gpgExitStatus
);
}
else
{
$this->displayTextInT able('proc_open () failed.');
exit;
}
return $encryptedConte nt;
}
Comment