Usage
Creating The Crypt_GPG Object
The Crypt_GPG class is the main entry point for using Crypt_GPG. To use GnuPG in your project, create an instance of Crypt_GPG and then call methods on the object to perform GPG actions.
The Crypt_GPG class supports several options, which may be specified in the constructor. Options may be used for the following:
Specifying Keyring Location
Sometimes, specifying the location of the keyring is required. One such
case case is when using Crypt_GPG from the context
of a Web page when the Web-server's user does not have a home directory, or
does not have write access to its home directory. This is often the case on
shared hosts. In this case, you should specify the GnuPG keyring location
as an existing writeable directory. This is done using the
homedir
option. For example:
<?php
require_once 'Crypt/GPG.php';
// Specify homedir as an existing writeable directory if the web user
// does not have a home directory, or if the web user's home directory
// is not writeable.
$gpg = new Crypt_GPG(array('homedir' => '/my/writeable/directory'));
?>
Showing Debug Information
If, for some reason, Crypt_GPG does not seem to work
correctly, detailed debugging information may be turned on. This is done
using the debug
option. When providing bug reports for
the Crypt_GPG package, you may be asked to turn on deubg
mode. Example:
<?php
require_once 'Crypt/GPG.php';
// Enable debug mode. This will dump a lot of output when Crypt_GPG
// actions are performed.
$gpg = new Crypt_GPG(array('debug' => true));
?>
Specifying the GnuPG Binary Location
Crypt_GPG works by talking to the GnuPG subprocess. As a
result, it needs to know the location of the GnuPG binary to work properly.
In most cases, Crypt_GPG will detect the location of the
GnuPG binary automatically. If the location is detected incorrectly, or if
the GnuPG binary is installed in a custom location, the
binary
option may be used. For example:
<?php
require_once 'Crypt/GPG.php';
// Specify custom location of GnuPG binary.
$gpg = new Crypt_GPG(array('binary' => '/home/joe/bin/gpg'));
?>
If an invalid binary location is specified, Crypt_GPG will throw an exception.