Crypt_GPG
[ class tree: Crypt_GPG ] [ index: Crypt_GPG ] [ all elements ]

Class: Crypt_GPG_Driver_GnuPG

Source Location: /Crypt_GPG-0.6.0/GPG/Driver/GnuPG.php

Class Overview

Crypt_GPG
   |
   --Crypt_GPG_Driver_GnuPG

PECL gnupg Crypt_GPG driver


Author(s):

Copyright:

  • 2008 silverorange

Methods


Inherited Variables

Inherited Methods

Class: Crypt_GPG

Crypt_GPG::__construct()
Creates a new Crypt_GPG object
Crypt_GPG::decrypt()
Decrypts string data using the given passphrase
Crypt_GPG::deletePrivateKey()
Deletes a private key from the keyring
Crypt_GPG::deletePublicKey()
Deletes a public key from the keyring
Crypt_GPG::encrypt()
Encrypts string data
Crypt_GPG::exportPublicKey()
Exports a public key from the keyring
Crypt_GPG::factory()
Static factory method to create a new GPG object using the specified backend driver
Crypt_GPG::getFingerprint()
Gets a key fingerprint from the keyring
Crypt_GPG::getKeys()
Gets the available keys in the keyring
Crypt_GPG::importKey()
Imports a public or private key into the keyring
Crypt_GPG::sign()
Signs data using the given key and passphrase
Crypt_GPG::verify()
Verifies signed data

Class Details

[line 119]
PECL gnupg Crypt_GPG driver

This driver uses the gnupg PECL extension to control the GPG process. The PECL extension must be installed and enabled for your PHP installation.

If you have PECL installed, you can install the gnupg extension using:

  1.  $ pecl install gnupg
You will need to have the gpgme development libraries installed on your system before building the PECL extension.

Unlike the native PHP Crypt_GPG driver, this implementation should work on Windows for operations requiring a passphrase (signing and decrypting). If these requirements are not needed, it is recommended to use the native PHP implementation as there are some drawbacks to the GnuPG driver.

Drawbacks to using the GnuPG driver are:

See the PHP gnupg documentation and PECL extension page.



[ Top ]


Method Detail

__construct (Constructor)   [line 165]

Crypt_GPG_Driver_GnuPG __construct( [array $options = array()])

Creates a new GPG object that uses the gnupg PECL extension to control the GPG process

Developers are encouraged to use the Crypt_GPG::factory() method to instantiate this class.

Available options for this driver are:

  • string homedir: The directory where the GPG keyring files are stored. If not specified, GPG uses the default of $HOME/.gnupg, where $HOME is the present user's home directory. This option only needs to be specified when $HOME/.gnupg is inappropriate.

  • Throws: PEAR_Exception if the gnupg PECL extension is missing or not loaded.
  • Access: public

Overrides Crypt_GPG::__construct() (Creates a new Crypt_GPG object)

Parameters:

array   $options   —  optional. An array of options used to create the GPG object. All options must be optional and are represented as key-value pairs.

[ Top ]

decrypt   [line 568]

string decrypt( string $encrypted_data, [string $passphrase = null])

Decrypts string data using the given passphrase

This method assumes the required private key is available in the keyring and throws an exception if the private key is not available. To add a private key to the keyring, use the Crypt_GPG::importKey() method.

  • Return: the decrypted data.
  • Throws: Crypt_GPG_KeyNotFoundException if the private key needed to decrypt the data is not in the user's keyring.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Throws: Crypt_GPG_NoDataException if specified data does not contain GPG encrypted data.
  • Throws: Crypt_GPG_BadPassphraseException if specified passphrase is incorrect or if a required passphrase is not specified.
  • Access: public

Overrides Crypt_GPG::decrypt() (Decrypts string data using the given passphrase)

Parameters:

string   $encrypted_data   —  the data to be decrypted.
string   $passphrase   —  optional. The passphrase of the private key used to encrypt the data. Only required if the private key requires a passphrase.

[ Top ]

deletePrivateKey   [line 360]

void deletePrivateKey( string $key_id)

Deletes a private key from the keyring

If more than one key fingerprint is avaliable for the specified $key_id (for example, if you use a non-unique uid) only the first private key is deleted.

Since the gnupg PECL extension does not support deleting private keys without also deleting the associated public keys, this method is handed off to the native PHP GPG driver.

  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Throws: Crypt_GPG_KeyNotFoundException if a private key with the given $key_id is not found.
  • Access: public

Overrides Crypt_GPG::deletePrivateKey() (Deletes a private key from the keyring)

Parameters:

string   $key_id   —  either the full uid of the private key, the email part of the uid of the private key or the key id of the private key. For example, "Test User (example) <test@example.com>", "test@example.com" or a hexidecimal string.

[ Top ]

deletePublicKey   [line 305]

void deletePublicKey( string $key_id)

Deletes a public key from the keyring

If more than one key fingerprint is avaliable for the specified $key_id (for example, if you use a non-unique uid) only the first public key is deleted.

  • Throws: Crypt_GPG_KeyNotFoundException if a private key with the given $key_id is not found.
  • Throws: Crypt_GPG_DeletePrivateKeyException if the specified public key has an associated private key on the keyring. The private key must be deleted first.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Access: public

Overrides Crypt_GPG::deletePublicKey() (Deletes a public key from the keyring)

Parameters:

string   $key_id   —  either the full uid of the public key, the email part of the uid of the public key or the key id of the public key. For example, "Test User (example) <test@example.com>", "test@example.com" or a hexidecimal string.

[ Top ]

encrypt   [line 507]

string encrypt( string $key_id, string $data, [boolean $armor = true])

Encrypts string data

Data is ASCII armored by default but may optionally be returned as binary.

  • Return: the encrypted data.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Throws: Crypt_GPG_KeyNotFoundException if the a key with the given $key_id is not found.
  • Access: public

Overrides Crypt_GPG::encrypt() (Encrypts string data)

Parameters:

string   $key_id   —  the full uid of the public key to use for encryption. For example, "Test User (example) <test@example.com>".
string   $data   —  the data to be encrypted.
boolean   $armor   —  optional. If true, ASCII armored data is returned; otherwise, binary data is returned. Defaults to true.

[ Top ]

exportPublicKey   [line 272]

string exportPublicKey( string $key_id, [boolean $armor = true])

Exports a public key from the keyring

The exported key remains on the keyring. To delete the public key, use Crypt_GPG::deletePublicKey().

If more than one key fingerprint is avaliable for the specified $key_id (for example, if you use a non-unique uid) only the first public key is exported.

Since the gnupg PECL extension does not support exporting keys, this method is handed off to the native PHP GPG driver.

  • Return: the public key data.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Throws: Crypt_GPG_KeyNotFoundException if a public key with the given $key_id is not found.
  • Access: public

Overrides Crypt_GPG::exportPublicKey() (Exports a public key from the keyring)

Parameters:

string   $key_id   —  either the full uid of the public key, the email part of the uid of the public key or the key id of the public key. For example, "Test User (example) <test@example.com>", "test@example.com" or a hexidecimal string.
boolean   $armor   —  optional. If true, ASCII armored data is returned; otherwise, binary data is returned. Defaults to true.

[ Top ]

getFingerprint   [line 448]

string getFingerprint( string $key_id, [integer $format = Crypt_GPG::FORMAT_NONE])

Gets a key fingerprint from the keyring

If more than one key fingerprint is avaliable (for example, if you use a non-unique user id) only the first key fingerprint is returned.

  • Return: the fingerprint of the key, or null if no fingerprint is found for the given $key_id.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Access: public

Overrides Crypt_GPG::getFingerprint() (Gets a key fingerprint from the keyring)

Parameters:

string   $key_id   —  either the full user id of the key, the email part of the user id of the key, or the key id of the key. For example, "Test User (example) <test@example.com>", "test@example.com" or a hexidecimal string.
integer   $format   —  optional. How the fingerprint should be formatted. Use Crypt_GPG::FORMAT_X509 for X.509 certificate format, Crypt_GPG::FORMAT_CANONICAL for the format used by GnuPG output and Crypt_GPG::FORMAT_NONE for no formatting. Defaults to Crypt_GPG::FORMAT_NONE.

[ Top ]

getKeys   [line 383]

array getKeys( [string $key_id = ''])

Gets the available keys in the keyring
  • Return: an array of Crypt_GPG_Key objects.
  • See: Crypt_GPG_Key
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Access: public

Overrides Crypt_GPG::getKeys() (Gets the available keys in the keyring)

Parameters:

string   $key_id   —  optional. Only keys with that match the specified pattern are returned. The pattern may be part of a user id, a key id or a key fingerprint. If not specified, all keys are returned.

[ Top ]

importKey   [line 214]

array importKey( string $data)

Imports a public or private key into the keyring

Keys may be removed from the keyring using Crypt_GPG::deletePublicKey() or Crypt_GPG::deletePrivateKey().

  • Return: an associative array containing the following elements:
    • fingerprint: the key fingerprint of the imported key,
    • public_imported: the number of public keys imported,
    • public_unchanged: the number of unchanged public keys,
    • private_imported: the number of private keys imported,
    • private_unchanged: the number of unchanged private keys.
  • Throws: Crypt_GPG_DuplicateKeyImportException if key is already in the keyring.
  • Throws: Crypt_GPG_NoDataException if the key data is missing or if the data is is not valid key data.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. File a bug report if these exceptions occur.
  • Access: public

Overrides Crypt_GPG::importKey() (Imports a public or private key into the keyring)

Parameters:

string   $data   —  the key data to be imported.

[ Top ]

sign   [line 666]

string sign( string $key_id, string $data, [string $passphrase = null], [boolean $mode = Crypt_GPG::SIGN_MODE_NORMAL], [boolean $armor = true])

Signs data using the given key and passphrase

Data may be signed using any one of the three available signing modes:

  • Return: the signed data, or the signature data if a detached signature is requested.
  • Throws: Crypt_GPG_KeyNotFoundException if the private key is not in the user's keyring. Signing data requires the private key.
  • Throws: Crypt_GPG_BadPassphraseException if specified passphrase is incorrect or if a required passphrase is not specified.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. file a bug report if these exceptions occur.
  • Access: public

Overrides Crypt_GPG::sign() (Signs data using the given key and passphrase)

Parameters:

string   $key_id   —  either the full uid of the private key, the email part of the uid of the private key or the key id of the private key. For example, "Test User (example) <test@example.com>", "test@example.com" or a hexidecimal string.
string   $data   —  the data to be signed.
string   $passphrase   —  optional. The passphrase of the private key used to sign the data. Only required if the private key requires a passphrase. Specify null for no passphrase.
boolean   $mode   —  otional. The data signing mode to use. Should be one of Crypt_GPG::SIGN_MODE_NORMAL, Crypt_GPG::SIGN_MODE_CLEAR or Crypt_GPG::SIGN_MODE_DETACHED. If not specified, defaults to Crypt_GPG::SIGN_MODE_NORMAL.
boolean   $armor   —  optional. If true, ASCII armored data is returned; otherwise, binary data is returned. Defaults to true. This has no effect if the mode Crypt_GPG::SIGN_MODE_CLEAR is used.

[ Top ]

verify   [line 738]

Crypt_GPG_Signature verify( string $signed_data, [string $signature = ''])

Verifies signed data

The Crypt_GPG::decrypt() method may be used to get the original message if the signed data is not clearsigned and does not have a detached signature.

  • Return: the signature details of the signed data. If the signature is valid, the $valid property of the returned object will be true.
  • See: Crypt_GPG_Signature
  • Throws: Crypt_GPG_NoDataException if the provided data is not signed data.
  • Access: public

Overrides Crypt_GPG::verify() (Verifies signed data)

Parameters:

string   $signed_data   —  the signed data to be verified.
string   $signature   —  optional. If verifying data signed using a detached signature, this must be the detached signature data. The data that was signed is specified in $signed_data.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:19:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.