Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 361255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:52:46+00:00 2026-05-12T12:52:46+00:00

I’m trying to use GNUPG and Crypt_GPG to encrypt data ready to be sent

  • 0

I’m trying to use GNUPG and Crypt_GPG to encrypt data ready to be sent across email to a client server but i’m having problems setting it up.

  1. I’ve installed GNUPG on the server, and it works just fine, located in /home/myserver/.gnupg
  2. I’ve installed Crypt_GPG into /home/myserver/php/Crypt and edited the various files to have absolute link references to each other. They work fine.
  3. I’ve used my server CPanel to create a test public/secret key. The key generated fine.

Here is my test code (with debug mode left on)

<?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, displayed and the fingerprint shows too.

The problem is with the second block of code – actually trying to encrypt something. I get these errors in the debug output. I won’t post the full output (its large) but I hope these are the salient points:

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

To me it looks like the Crypt_GPG is having issues selecting what it needs from the GNUPG key? It appears to find the key correctly, but it falls over with the passphrase. Is this an error with my understanding and code, or is this because CPanel and Apache are different users or something?

Need a bit of guidance, thanks 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:52:48+00:00Added an answer on May 12, 2026 at 12:52 pm

    The examples show you how to specify the passphrase:

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

    Check the documentation for more examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.