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

Class: Crypt_GPG_KeyGenerator

Source Location: /Crypt_GPG-1.4.0b4/Crypt/GPG/KeyGenerator.php

Class Overview

Crypt_GPGAbstract
   |
   --Crypt_GPG_KeyGenerator

GnuPG key generator


Author(s):

Copyright:

  • 2005-2013 silverorange

Variables

Methods


Inherited Variables

Inherited Methods

Class: Crypt_GPGAbstract

Crypt_GPGAbstract::__construct()
Creates a new GPG object
Crypt_GPGAbstract::setEngine()
Sets the I/O engine to use for GnuPG operations
Crypt_GPGAbstract::_getKeys()
Gets the available keys in the keyring

Class Details

[line 83]
GnuPG key generator

This class provides an object oriented interface for generating keys with the GNU Privacy Guard (GPG).

Secure key generation requires true random numbers, and as such can be slow. If the operating system runs out of entropy, key generation will block until more entropy is available.

If quick key generation is important, a hardware entropy generator, or an entropy gathering daemon may be installed. For example, administrators of Debian systems may want to install the 'randomsound' package.

This class uses the experimental automated key generation support available in GnuPG. See doc/DETAILS in the GPG distribution for detailed information on the key generation format.



[ Top ]


Class Variables

$errorHandler =  null

[line 181]

The GnuPG error handler to use for key generation



[ Top ]

$expirationDate =  0

[line 94]

The expiration date of generated keys

Type:   integer


[ Top ]

$keyAlgorithm =  Crypt_GPG_SubKey::ALGORITHM_DSA

[line 112]

The algorithm for generated primary keys

Type:   integer


[ Top ]

$keySize =  1024

[line 121]

The size of generated primary keys

Type:   integer


[ Top ]

$keyUsage =  6

[line 133]

The usages of generated primary keys

This is a bitwise combination of the usage constants in Crypt_GPG_SubKey.


Type:   integer


[ Top ]

$passphrase =  ''

[line 103]

The passphrase of generated keys

Type:   string


[ Top ]

$statusHandler =  null

[line 172]

The GnuPG status handler to use for key generation



[ Top ]

$subKeyAlgorithm =  Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC

[line 142]

The algorithm for generated sub-keys

Type:   integer


[ Top ]

$subKeySize =  2048

[line 151]

The size of generated sub-keys

Type:   integer


[ Top ]

$subKeyUsage =  Crypt_GPG_SubKey::USAGE_ENCRYPT

[line 163]

The usages of generated sub-keys

This is a bitwise combination of the usage constants in Crypt_GPG_SubKey.


Type:   integer


[ Top ]



Method Detail

__construct (Constructor)   [line 272]

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

Creates a new GnuPG key generator

Available options are:

  • string homedir - the directory where the GPG keyring files are stored. If not specified, Crypt_GPG uses the default of ~/.gnupg.
  • string publicKeyring - the file path of the public keyring. Use this if the public keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/pubring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string privateKeyring - the file path of the private keyring. Use this if the private keyring is not in the homedir, or if the keyring is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the keyring with this option (/foo/bar/secring.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string trustDb - the file path of the web-of-trust database. Use this if the trust database is not in the homedir, or if the database is in a directory not writable by the process invoking GPG (like Apache). Then you can specify the path to the trust database with this option (/foo/bar/trustdb.gpg), and specify a writable directory (like /tmp) using the homedir option.
  • string binary - the location of the GPG binary. If not specified, the driver attempts to auto-detect the GPG binary location using a list of known default locations for the current operating system. The option gpgBinary is a deprecated alias for this option.
  • string agent - the location of the GnuPG agent binary. The gpg-agent is only used for GnuPG 2.x. If not specified, the engine attempts to auto-detect the gpg-agent binary location using a list of know default locations for the current operating system.
  • boolean debug - whether or not to use debug mode. When debug mode is on, all communication to and from the GPG subprocess is logged. This can be

  • Throws: Crypt_GPG_FileException if the homedir does not exist and cannot be created. This can happen if homedir is not specified, Crypt_GPG is run as the web user, and the web user has no home directory. This exception is also thrown if any of the options publicKeyring, privateKeyring or trustDb options are specified but the files do not exist or are are not readable. This can happen if the user running the Crypt_GPG process (for example, the Apache user) does not have permission to read the files.
  • Throws: PEAR_Exception if the provided binary is invalid, or if no binary is provided and no suitable binary could be found.
  • Throws: PEAR_Exception if the provided agent is invalid, or if no agent is provided and no suitable gpg-agent cound be found.
  • Access: public

Overrides Crypt_GPGAbstract::__construct() (Creates a new GPG object)

Parameters:

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

[ Top ]

generateKey   [line 589]

Crypt_GPG_Key generateKey( string|Crypt_GPG_UserId $name, [string $email = ''], [string $comment = ''])

Generates a new key-pair in the current keyring

Secure key generation requires true random numbers, and as such can be solw. If the operating system runs out of entropy, key generation will block until more entropy is available.

If quick key generation is important, a hardware entropy generator, or an entropy gathering daemon may be installed. For example, administrators of Debian systems may want to install the 'randomsound' package.

  • Return: the newly generated key.
  • Throws: Crypt_GPG_Exception if an unknown or unexpected error occurs. Use the debug option and file a bug report if these exceptions occur.
  • Throws: Crypt_GPG_KeyNotCreatedException if the key parameters are incorrect, if an unknown error occurs during key generation, or if the newly generated key is not found in the keyring.
  • Access: public

Parameters:

string|Crypt_GPG_UserId   $name     either a Crypt_GPG_UserId object, or a string containing the name of the user id.
string   $email     optional. If $name is specified as a string, this is the email address of the user id.
string   $comment     optional. If $name is specified as a string, this is the comment of the user id.

[ Top ]

getUsage   [line 731]

string getUsage( integer $usage)

Builds a GnuPG key usage string suitable for key generation

See doc/DETAILS in the GPG distribution for detailed information on the key usage format.

  • Return: the key usage string.
  • Access: protected

Parameters:

integer   $usage     a bitwise combination of the key usages. This is a combination of the Crypt_GPG_SubKey::USAGE_* constants.

[ Top ]

getUserId   [line 773]

Crypt_GPG_UserId getUserId( string|Crypt_GPG_UserId $name, [string $email = ''], [string $comment = ''])

Gets a user id object from parameters
  • Return: a user id object for the specified parameters.
  • Access: protected

Parameters:

string|Crypt_GPG_UserId   $name     either a Crypt_GPG_UserId object, or a string containing the name of the user id.
string   $email     optional. If $name is specified as a string, this is the email address of the user id.
string   $comment     optional. If $name is specified as a string, this is the comment of the user id.

[ Top ]

setErrorHandler   [line 547]

Crypt_GPG_KeyGenerator setErrorHandler( Crypt_GPG_KeyGeneratorErrorHandler $handler)

Sets the error handler to use for key generation

Normally this method does not need to be used. It provides a means for dependency injection.

  • Return: the current object, for fluent interface.
  • Access: public

Parameters:

Crypt_GPG_KeyErrorHandler   $handler     the key error handler to use.

[ Top ]

setExpirationDate   [line 302]

Crypt_GPG_KeyGenerator setExpirationDate( string|integer $date)

Sets the expiration date of generated keys
  • Return: the current object, for fluent interface.
  • Throws: InvalidArgumentException if the date is not a valid format, or if the date is not at least one day in the future, or if the date is greater than 2038-01-19T03:14:07.
  • Access: public

Parameters:

string|integer   $date     either a string that may be parsed by PHP's strtotime() function, or an integer timestamp representing the number of seconds since the UNIX epoch. This date must be at least one date in the future. Keys that expire in the past may not be generated. Use an expiration date of 0 for keys that do not expire.

[ Top ]

setKeyParams   [line 380]

Crypt_GPG_KeyGenerator setKeyParams( integer $algorithm, [integer $size = 0], [integer $usage = 0])

Sets the parameters for the primary key of generated key-pairs
  • Return: the current object, for fluent interface.
  • Access: public

Parameters:

integer   $algorithm     the algorithm used by the key. This should be one of the Crypt_GPG_SubKey::ALGORITHM_* constants.
integer   $size     optional. The size of the key. Different algorithms have different size requirements. If not specified, the default size for the specified algorithm will be used. If an invalid key size is used, GnuPG will do its best to round it to a valid size.
integer   $usage     optional. A bitwise combination of key usages. If not specified, the primary key will be used only to sign and certify. This is the default behavior of GnuPG in interactive mode. Use the Crypt_GPG_SubKey::USAGE_* constants here. The primary key may be used to certify even if the certify usage is not specified.

[ Top ]

setPassphrase   [line 349]

Crypt_GPG_KeyGenerator setPassphrase( string $passphrase)

Sets the passphrase of generated keys
  • Return: the current object, for fluent interface.
  • Access: public

Parameters:

string   $passphrase     the passphrase to use for generated keys. Use null or an empty string for no passphrase.

[ Top ]

setStatusHandler   [line 526]

Crypt_GPG_KeyGenerator setStatusHandler( Crypt_GPG_KeyGeneratorStatusHandler $handler)

Sets the status handler to use for key generation

Normally this method does not need to be used. It provides a means for dependency injection.

  • Return: the current object, for fluent interface.
  • Access: public

Parameters:

Crypt_GPG_KeyStatusHandler   $handler     the key status handler to use.

[ Top ]

setSubKeyParams   [line 455]

Crypt_GPG_KeyGenerator setSubKeyParams( integer $algorithm, [integer $size = ''], [integer $usage = 0])

Sets the parameters for the sub-key of generated key-pairs
  • Return: the current object, for fluent interface.
  • Access: public

Parameters:

integer   $algorithm     the algorithm used by the key. This should be one of the Crypt_GPG_SubKey::ALGORITHM_* constants.
integer   $size     optional. The size of the key. Different algorithms have different size requirements. If not specified, the default size for the specified algorithm will be used. If an invalid key size is used, GnuPG will do its best to round it to a valid size.
integer   $usage     optional. A bitwise combination of key usages. If not specified, the sub-key will be used only to encrypt. This is the default behavior of GnuPG in interactive mode. Use the Crypt_GPG_SubKey::USAGE_* constants here.

[ Top ]


Documentation generated on Wed, 13 Mar 2013 18:30:10 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.