How to use GNUPG and Crypt_GPG

I'm trying to use GNUPG and Crypt_GPG to encrypt data ready to be emailed to the client server, but I'm having trouble getting it set up.

  • I have installed GNUPG on the server and it works fine, located at /home/myserver/.gnupg

  • I installed Crypt_GPG in /home/myserver/php/Crypt

    and edited various files to have absolute links to each other. They work great.
  • I used the CPanel server to generate a test public / private key. The generated key.

Here is my test code (with debug mode enabled)

<?php
require_once '/home/myserver/php/Crypt/GPG.php';

$gpg = new Crypt_GPG(array('homedir' => '/home/myserver/.gnupg', 'debug' => true));
echo "My public key is: ", $gpg->exportPublicKey('info@test.co.uk'), "<br>";
echo "My key fingerprint is: ", $gpg->getFingerprint('info@test.co.uk', Crypt_GPG::FORMAT_CANONICAL), "<br>";

$data = 'Hello, World!';
$gpg->addSignKey('info@test.co.uk');
$signedData = $gpg->sign($data, Crypt_GPG::SIGN_MODE_CLEAR);
echo "<br><br>Clearsigned message is: ", $signedData, "\n";

?>

      

The first section of code works well - the public key is retrieved, and the fingerprint is displayed and displayed.

The problem with the second block of code is actually trying to encrypt something. I am getting these errors in the debug output. I won't post the full output (its large), but I hope these are the highlights:

Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730
Crypt_GPG DEBUG: STATUS: USERID_HINT EEE2DCBB741D9730 Test Key (Test Key)
Crypt_GPG DEBUG: STATUS: NEED_PASSPHRASE EEE2DCBB741D9730 EEE2DCBB741D9730 17 0
Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG is ready for command data
Crypt_GPG DEBUG: => about to write 1 bytes to GPG command
Crypt_GPG DEBUG: => wrote 1
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 44 bytes
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 122 bytes
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730

      

and then later:

Crypt_GPG DEBUG: END PROCESSING
Crypt_GPG DEBUG: CLOSING SUBPROCESS
Crypt_GPG DEBUG: => subprocess returned an unexpected exit code: 2

Fatal error: Uncaught <table border="1" cellspacing="0"> <tr><td colspan="3" bgcolor="#ff9999"> <b>Crypt_GPG_BadPassphraseException</b>: Cannot sign data. Incorrect passphrase provided. in <b>/home/myserver/php/Crypt/GPG.php</b> on line <b>1054</b></td></tr> <tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr> <tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td><td align="center" bgcolor="#cccccc"><b>Function</b></td><td align="center" bgcolor="#cccccc"><b>Location</b></td></tr> <tr><td align="center">0</td><td>Crypt_GPG->_sign('Hello, World!', false, null, 2, true)</td><td>/home/myserver/php/Crypt/GPG.php:1054</td></tr> <tr><td align="center">1</td><td>Crypt_GPG->sign('Hello, World!', 2)</td><td>/home/myserver/public_html/email.php:7</td></tr> <tr><td align="center">2</td><td>{main}</td><td>&nbsp;</td></tr> </table> thrown in /home/myserver/php/Crypt/GPG.php on line 1837

      

It seems to me that Crypt_GPG is having trouble deciding what it needs from the GNUPG key? It seems to find the key correctly, but it crashes with a passphrase. Is this a mistake with my understanding and code, or is it because CPanel and Apache are different users or something?

Need some guidance, thanks;)

+2


source to share


1 answer


examples shows you how to specify a passphrase:

$gpg->addSignKey('test@example.com', 'test');

      



More on the documentation .

+2


source







All Articles