Inspired by http://devzone.zend.com/1278/using-gnupg-with-php/ and with help @ PHP ASCII Armored PGP encrypted string
I was able to GnuPG-encrypt a string with a 3rd party public key when running in CLI.
PHP 5.2.10 (cli) (built: Nov 13 2009 11:44:05)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
but...
I get "exit signal Segmentation fault (11)" when invoking addencryptkey running the same script through the webserver (Apache on CentOS).
apache errorl log
[notice] child pid 30682 exit signal Segmentation fault (11)
nothing of value in syslog...
any pointers? thanks!
code (nothing earth shattering):
// GnuPG code
putenv("GNUPGHOME=/opt/.gnupg/");
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$gpg -> setarmor(1);
try
{
$info = $gpg -> addencryptkey("KEY");
var_dump($info);
$enc = $gpg -> encrypt($token);
var_dump($enc);
}
catch (Exception $e) {
echo 'ERROR: ' . $e->getMessage();
}
drwxr-xr-x 2 root root 4096 Jan 14 11:29 .gnupg
[root@dev-lamp01 opt]# ll .gnupg/
total 28
-rw-rw-rw- 1 root root 9224 Jan 14 10:23 gpg.conf
-rw-rw-rw- 1 root root 325 Jan 14 10:25 pubring.gpg
-rw-rw-rw- 1 root root 0 Jan 14 10:20 pubring.gpg~
-rw-rw-rw- 1 root root 600 Jan 14 11:29 random_seed
-rw-rw-rw- 1 root root 0 Jan 14 10:20 secring.gpg
-rw-rw-rw- 1 root root 1200 Jan 14 10:25 trustdb.gpg
oh well - my fault - as soon as I did
chmod -R 777
on my GNUPGHOME - it all worked
thought it was happy with 666 (and CLI was happy with just rw)