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

Class: Crypt_GPG

Source Location: /Crypt_GPG-0.3.10/GPG.php

Class Overview


A class to use GPG from PHP


Author(s):

Copyright:

  • 2005-2007 silverorange

Methods


Child classes:

Crypt_GPG_Driver_Php
Native PHP Crypt_GPG driver

Inherited Variables

Inherited Methods


Class Details

[line 79]
A class to use GPG from PHP

This class provides an object oriented interface to GNU Privacy Guard (GPG).

Though GPG can support symmetric-key cryptography, this class is intended only to facilitate public-key cryptography.



[ Top ]


Method Detail

decrypt   [line 464]

string decrypt( string $encrypted_data, string $passphrase)

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.
  • Abstract:
  • Throws: Crypt_GPG_KeyNotFoundException if the private key needed to decrypt the data is not in the user's keyring.
  • Throws: Crypt_GPG_NoDataException if specified data does not contain GPG encrypted data.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Throws: Crypt_GPG_BadPassphraseException if specified passphrase is incorrect or if no passphrase is specified.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::decrypt()
Decrypts string data using the given passphrase

Parameters:

string   $encrypted_data   —  the data to be decrypted.
string   $passphrase   —  the passphrase of the private key used to encrypt the data.

[ Top ]

deletePrivateKey   [line 293]

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.

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

Overridden in child classes as:

Crypt_GPG_Driver_Php::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 266]

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.

  • Abstract:
  • Throws: Crypt_GPG_KeyNotFoundException if a public key with the given $key_id is not found.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::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 432]

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.

If this method throws a Crypt_GPG_MissingSelfSignatureException, the public key needs to be signed. Keys may be manually signed using the shell command:

  1. gpg --sign-key &lt;key-id&gt; &lt;named-user&gt;

  • Return: the encrypted data.
  • Abstract:
  • Throws: Crypt_GPG_KeyNotFoundException if the a key with the given $key_id is not found.
  • Throws: Crypt_GPG_UnsignedKeyException if specified key is not signed.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Throws: Crypt_GPG_MissingSelfSignatureException if specified key is not self-signed (verified by the user).
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::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 ]

__construct (Constructor)   [line 213]

Crypt_GPG __construct( [array $options = null])

Creates a new Crypt_GPG object
  • Abstract:
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::__construct()
Creates a new GPG object that uses PHP's native process manipulation functions to control the GPG process

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 ]

factory   [line 184]

Crypt_GPG factory( [string $driver = 'php'], [array $options = array()])

Static factory method to create a new GPG object using the specified backend driver

This allows developers to write code using a standard interface and optionally switch to a PECL-based implementation with minimal fuss at a later date.

  • Return: a GPG object powered by the speficied driver.
  • Access: public

Parameters:

string   $driver   —  optional. The name of the driver to use. Valid driver names are 'php' for a native PHP driver and 'gnupg' for a PECL-powered driver. If not specified, the native PHP driver is used.
array   $options   —  optional. An array of options passed to the driver's constructor. All options must be optional and are represented as key-value pairs. See documentation of a specific driver for details on what options are available.

[ Top ]

getPrivateFingerprint   [line 393]

string getPrivateFingerprint( string $key_id, [boolean $separator = ''])

Gets a private key fingerprint from the keyring

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

Only private key fingerprints are returned. See Crypt_GPG::getPublicFingerprint() to get the fingerprint of a public key.

  • Return: the fingerprint of the private key, or null if no fingerprint is found for the given private key identifier.
  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::getPrivateFingerprint()
Gets a private key fingerprint 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   $separator   —  optional. A string placed between the public key fingerprint components to make the fingerprint easier to read. If not specified, the components of the fingerprint are not separated.

[ Top ]

getPrivateKeys   [line 325]

array getPrivateKeys( )

Gets the available private keys in the keyring
  • Return: an array of Crypt_GPG_Key objects.
  • See: Crypt_GPG_Key
  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::getPrivateKeys()
Gets the available private keys in the keyring

[ Top ]

getPublicFingerprint   [line 359]

string getPublicFingerprint( string $key_id, [boolean $separator = ''])

Gets a public key fingerprint from the keyring

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

Only public key fingerprints are returned. See Crypt_GPG::getPrivateFingerprint() to get the fingerprint of a private key.

  • Return: the fingerprint of the public key, or null if no fingerprint is found for the given public key identifier.
  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::getPublicFingerprint()
Gets a public key fingerprint 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   $separator   —  optional. A string placed between the public key fingerprint components to make the fingerprint easier to read. If not specified, the components of the fingerprint are not separated.

[ Top ]

getPublicKeys   [line 309]

array getPublicKeys( )

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

Overridden in child classes as:

Crypt_GPG_Driver_Php::getPublicKeys()
Gets the available public keys in the keyring

[ Top ]

importKey   [line 239]

void 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().

  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • 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.
  • Access: public

Overridden in child classes as:

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

Parameters:

string   $data   —  the key data to be imported.

[ Top ]

sign   [line 508]

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

Signs data using the given key and passphrase

Data my be signed using and one of the three available signing modes:

  • Return: the signed data or signature data is a detached signature is requested.
  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • 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 no passphrase is specified.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::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   —  the passphrase of the user's private key.
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 540]

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
  • Abstract:
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use Crypt_GPG::$debug and file a bug report if these exceptions occur.
  • Throws: Crypt_GPG_NoDataException if the provided data is not signed data.
  • Access: public

Overridden in child classes as:

Crypt_GPG_Driver_Php::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:14:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.