totus Posted October 30, 2009 Share Posted October 30, 2009 I am writing php scripts to extract gpg encrypted parameters from a URL. I'm not sure if this is a coding problem or a package install problem but I'm at a loss at this point. There is so little documentation of gpg php use. Here it goes: [root@mirage enrollment]# php encrypt.php PHP Warning: gnupg_addencryptkey(): get_key failed in /var/www/vhosts/somedomain.com/httpdocs/enrollment/encrypt.php on line 10 PHP Warning: gnupg_encrypt(): no key for encryption set in /var/www/vhosts/somedomain.com/httpdocs/enrollment/encrypt.php on line 13 /var/www/.gnupg [root@mirage enrollment]# gpg --homedir /var/www/.gnupg --fingerprint gpg: WARNING: unsafe ownership on homedir `/var/www/.gnupg' /var/www/.gnupg/pubring.gpg --------------------------- pub 1024D/24F0C25E 2009-10-29 Key fingerprint = 61EC B598 C01B 3DD4 2543 FB1A 1A16 8972 24F0 C25E uid dummy <[email protected]> sub 2048g/3F9A5055 2009-10-29 [root@mirage enrollment]# cat encrypt.php <?php $gpg = new gnupg(); $gpg -> seterrormode(gnupg::ERROR_EXCEPTION); // throw an exception in case of an error // set the environment so gnupg can find the keyring putenv("GNUPGHOME=/var/www/.gnupg"); $res = gnupg_init(); gnupg_seterrormode($res,GNUPG_ERROR_WARNING); // raise a PHP-Warning in case of an error gnupg_addencryptkey($res,"61ECB598C01B3DD42543FB1A1A16897224F0C25E"); #gnupg_addencryptkey($res,"61EC B598 C01B 3DD4 2543 FB1A 1A16 8972 24F0 C25E"); #gnupg_addencryptkey($res,"5C798B98314176C041DD66324A83C80EF1817BFB"); $enc = gnupg_encrypt($res, "just a test"); echo $enc; echo getenv("GNUPGHOME"). "\n"; ?> [root@mirage enrollment]# ls -al /var/www/.gnupg total 32 drwxrwxrwx 2 apache apache 4096 Oct 29 11:39 . drwxr-xr-x 11 root root 4096 Oct 28 20:42 .. -rwxrwxrwx 1 apache apache 1155 Oct 28 20:47 pubring.gpg -rwxrwxrwx 1 apache apache 1155 Oct 28 20:47 pubring.gpg~ -rwxrwxrwx 1 apache apache 600 Oct 28 20:47 random_seed -rwxrwxrwx 1 apache apache 1304 Oct 28 20:47 secring.gpg -rwxrwxrwx 1 apache apache 1280 Oct 28 20:47 trustdb.gpg [root@mirage enrollment]# php -m | grep gnugp [root@mirage enrollment]# php -m [root@mirage enrollment]# php -m | grep gnupg gnupg <--proof gnupg module is loaded. References: http://pecl.php.net/bugs/bug.php?id=11371 http://devzone.zend.com/article/3753 http://www.brandonchecketts.com/archives/gnupg-encryption-with-php Notes: I've tried both gnupgme as shown above as well as an attempt to use crypt_gpg below. I've triple checked the keys as well. [root@mirage enrollment]# php test.php PHP Warning: require_once(Crypt/GPG/VerifyStatusHandler.php): failed to open stream: No such file or directory in /usr/share/pear/Crypt/GPG.php on line 61 PHP Fatal error: require_once(): Failed opening required 'Crypt/GPG/VerifyStatusHandler.php' (include_path='.:') in /usr/share/pear/Crypt/GPG.php on line 61 [root@mirage enrollment]# more test.php <?php require_once '/usr/share/pear/Crypt/GPG.php'; // Specify homedir as an existing writeable directory if the web user // does not have a home directory, or if the web user's home directory // is not writeable. $gpg = new Crypt_GPG(array('debug' => true)); $gpg = new Crypt_GPG(array('homedir' => '/var/www/.gnupg')); ?> 2 day obsession Link to comment https://forums.phpfreaks.com/topic/179576-gnupgme-and-crypt_gpg-proplems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.