I am completely new to using GNUPG. I've installed it successfully on the server using YUM and WHM's built-in module installer.
I am attempting to import a key, and then use that to encrypt a file that will be SFTP'ed to someone else's server nightly. I have followed tutorials on setting the code up but cannot get past this point. I'm not really finding any helpful explanations as to why things would not work as described. I have followed info found in this question: Encrypt files using PGP in PHP? . Unfortunately, the people who wrote the info assumed it would work correctly the first time. I've also found other helpful pages such as http://devzone.zend.com/1278/using-gnupg-with-php/ which unfortunately also did not give error information.
First, let me say that the GNUPGHOME
path is not right. I actually am unsure where to point that to with the install I just did and just copied over files from another account directory to this one. I could not find info on how to set that up correctly and was hoping I'd just be able to import the new key into these files and use them without an issue. The code I am currently using is:
putenv("GNUPGHOME=/home/smlivere/public_html/tmp/.gnupg");
echo "GetEnv: ".getenv("GNUPGHOME")."<br/><br/>";
echo "Is Dir: ".is_dir(getenv("GNUPGHOME"))."<br/><br/>";
$pubkey = "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (MingW32)
[public key data]
-----END PGP PUBLIC KEY BLOCK-----";
$enc = (null);
// create new GnuPG object
$gpg = new gnupg();
// throw exception if error occurs
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
try {
$info = $gpg->import($pubkey);
echo "gnupg_import RTV = <br/><pre>\n";
var_dump($rtv);
echo gnupg_geterror($res);
echo "</pre>\n";
} catch (Exception $e) {
echo 'ERROR: ' . $e->getMessage()."<br/>";
echo "The exception code is: " . $e->getCode()."<br/>";
echo "The exception was created on line: " . $e->getLine()."<br/>";
echo "Stack Trace:<br/><pre>\n";
print_r($e->getTrace());
echo "</pre>\n";
}
I am getting back:
GetEnv: /home/smlivere/public_html/tmp/.gnupg
Is Dir: 1
ERROR: import failed
The exception code is: 0
The exception was created on line: 147
Stack Trace:
Array
(
[0] => Array
(
[file] => /home/smlivere/public_html/crons/export_dvm.php
[line] => 147
[function] => import
[class] => gnupg
[type] => ->
[args] => Array
(
[0] => -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (MingW32)
[public key data]
-----END PGP PUBLIC KEY BLOCK-----
)
)
[1] => Array
(
[file] => /home/smlivere/public_html/crons/export_dvm.php
[line] => 5
[function] => encrypt_file
[args] => Array
(
)
)
)
I'm assuming that my biggest issue is just the GNUPGHOME
but cannot honestly say. I wish there was more info on this out there. If anyone can help I would greatly appreciate it.
Thanks, James