TheosLogic Productions
TheosLogic Productions
Nathan's Wisements:      
Warning: Dates in Calendar are closer than they appear.
PHP / GPG encryption tools
© Copyright 2010 :: Nathan Ho
[ Back to Main Page ]

Using the PHP-GPG function is very simple. Just grab a copy of one of the two scripts, adjust the appropriate variables at the top:

  • $gpgdir :: path/location of your GPG keyring on the webserver
  • $gpgbin :: path/location of the GPG binary (optional auto-detection attempt, if desired).
  • $errLog :: path/location to the error log file for the proc_open command (for proc_open version only)

Then, include the file into the script where you need to use it:

include("./gpg.inc.php");

And then make the call with the appropriate data bits:

$encrypted = gpgit($data, $pgpkeys);

This function takes two arguments:

  1. Data ($data) to be encrypted
  2. a single variable or array of ($pgpkeys) PGP keys of target recipients (can be either PGP IDs or unique email addresses)

and returns the encrypted text into the variable you specify ($encrypted)! PGP Keys may be submitted as email addresses or PGP IDs, or a mixture of both. If no valid keys are submitted, the script will exit with an appropriate error and stop there.

PHP FUNCTION FILES

USE THESE SCRIPTS AT YOUR OWN RISK! I make no promises about the security of this script, nor do I guarantee it will work on any platform (or with any given version of GPG). While I have tried to ensure reasonable precautions to make these scripts as stable and secure as I can - you have been warned!

These scripts are open-source and free (no cost). You may do with it what you wish, as long as you leave the copyright data at the top in place.