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 9108429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:48:24+00:00 2026-06-17T02:48:24+00:00

I need to PGP encrypt and ASCII armor a small string/token within a MediaWiki

  • 0

I need to PGP encrypt and ASCII armor a small string/token within a MediaWiki environment using a public key provided to me by a third party. This gives me:

  • need to use PHP
  • better to stay away from exec_shell() … true?
  • web server environment

I am planning to use GnuPG lib after reading this:
http://devzone.zend.com/1278/using-gnupg-with-php/

What user should have PGP public key stored in their .gnupg folder?


UPDATE 1

so far I am testing hard-coding public key in (for now, just to test it out)

// GnuPG stuff
putenv("GNUPGHOME=/tmp");
$pubkey = "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.6 (GNU/Linux)
...key...
-----END PGP PUBLIC KEY BLOCK-----";

$ token="some text";
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION); 

try 
{
    $info = $gpg->import($pubkey);
//  var_dump($info); // to see fingerprint
    $info = $gpg -> addencryptkey("...fingerprint...");
    $enc = $gpg -> encrypt($token);
} 
catch (Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
}


$token = urlencode($enc);
echo $token, "\n";

it seems to encrypt, now I just need to figure out if I need/can strip

Encrypted Data: -----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.5 (GNU/Linux)

as I am encrypting a token for a URL

  • 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-06-17T02:48:25+00:00Added an answer on June 17, 2026 at 2:48 am

    Ascii-armored output can be enabled using PHP’s gnupg-functions. Have a look at setarmor.

    Add this line, probably best directly after creating your $gpg object:

    $gpg -> setarmor(1);
    

    But the documentation says ascii armoring would be default; what output do you get and which do you want? Sending ascii armored is convenient when mailing; otherwise you usually choose the smaller binary format directly. Never seen ascii-armored OpenPGP with “headers” stripped.


    To your smaller questions:

    better to stay away from exec_shell() … true?

    If it is disabled anyway, there is no decision on that. As long as PHP’s gnupg-functions have all functionality you need, prefer them; they save you from the hassle interfacing gpg (there is no direct API but the command line tools). Chance to introduce any exploits are smaller, too.

    What user should have PGP public key stored in their .gnupg folder?

    Choose an arbitrary folder readable (possible not writable?) for the webserver but non-reachable using HTTP (so nobody will be able to fetch your keys). It seems you already realized how to setup this path.

    it seems to encrypt, now I just need to figure out if I need/can strip

    [snip]

    I’d use some regex for this.

    preg_match('/[\n\r]([=\n\r[:alnum:]]+)[\n\r]/', $token, $matches);
    

    should do; maybe its more elegant to strip all lines either empty or containing a slash or colon.

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

Sidebar

Related Questions

I need to encrypt a stream with pgp using the bouncycastle provider. All of
We need to PGP encrypt files and send them over FTP to a third
Need to use PGP/GnuPG to encrypt.can suggest what the Python packages to use that.
I am working on PGP encryption/decryption using 'bouncycastle'. Do encrypt I understand that i
I have a pgp-encrypted file that I need to extract data from at runtime.
Im implementing users account in my website.I need to encrypt passwords from new members,however
Need a little help with string formatting... I have a string like this: Bmw
Need your suggestion on php/mysql software. I develop PHP websites using Dreamweaver, I also
Need to be able to read an Excel file uploaded using FileUploadControl in ASP.NET.
Need to make the site http://www.example.com/testimonials.htm to http://www.example.com/testimonials using .htaccess. Please help

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.