Horde_Crypt_Pgp:: provides a framework for Horde applications to interact
with the GNU Privacy Guard program ("GnuPG"). GnuPG implements the OpenPGP
standard (RFC 2440).
GnuPG Website: http://www.gnupg.org/
This class has been developed with, and is only guaranteed to work with,
Version 1.21 or above of GnuPG.
Copyright 2002-2012 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.
Methods summary
public
|
#
__construct( array $params = array() )
Constructor.
Parameters
- $params
- The following parameters:
<pre><span class="php-quote">'program'</span> - (string) [REQUIRED] The path to the GnuPG binary.
<span class="php-quote">'proxy_host - (string) Proxy host.
'</span>proxy_port - (integer) Proxy port.</pre>
Throws
InvalidArgumentException
Overrides
|
public
array
|
#
generateKey( string $realname, string $email, string $passphrase, string $comment = '', integer $keylength = 1024, integer $expire = null )
Generates a personal Public/Private keypair combination.
Generates a personal Public/Private keypair combination.
Parameters
- $realname
- The name to use for the key.
- $email
- The email to use for the key.
- $passphrase
- The passphrase to use for the key.
- $comment
- The comment to use for the key.
- $keylength
- The keylength to use for the key.
- $expire
- <p>The expiration date (UNIX timestamp). No
expiration if empty (since 1.1.0).</p>
Returns
array An array consisting of:
Key Value
--------------------------
'public' => Public Key
'private' => Private Key
Throws
|
public
array
|
#
pgpPacketInformation( string $pgpdata )
Returns information on a PGP data block.
Returns information on a PGP data block.
Parameters
- $pgpdata
- The PGP data block.
Returns
array An array with information on the PGP data block. If an
element is not present in the data block, it will
likewise not be set in the array.
Array Format:
-------------
[public_key]/[secret_key] => Array
(
[created] => Key creation - UNIX timestamp
[expires] => Key expiration - UNIX timestamp (0 = never expires)
[size] => Size of the key in bits
)
[keyid] => Key ID of the PGP data (if available)
16-bit hex value (as of Horde 3.2)
[signature] => Array (
[id{n}/'_SIGNATURE'] => Array (
[name] => Full Name
[comment] => Comment
[email] => E-mail Address
[keyid] => 16-bit hex value (as of Horde 3.2)
[created] => Signature creation - UNIX timestamp
[expires] => Signature expiration - UNIX timestamp
[micalg] => The hash used to create the signature
[sig_{hex}] => Array [details of a sig verifying the ID] (
[created] => Signature creation - UNIX timestamp
[expires] => Signature expiration - UNIX timestamp
[keyid] => 16-bit hex value (as of Horde 3.2)
[micalg] => The hash used to create the signature
)
)
)
Each user ID will be stored in the array 'signature' and have data
associated with it, including an array for information on each
signature that has signed that UID. Signatures not associated with a
UID (e.g. revocation signatures and sub keys) will be stored under the
special keyword '_SIGNATURE'.
Throws
|
public
string
|
#
pgpPrettyKey( string $pgpdata )
Returns human readable information on a PGP key.
Returns human readable information on a PGP key.
Parameters
- $pgpdata
- The PGP data block.
Returns
string Tabular information on the PGP key.
Throws
|
public
array
|
#
pgpPacketSignature( string $pgpdata, string $email )
Returns only information on the first ID that matches the email address
input.
Returns only information on the first ID that matches the email address
input.
Parameters
- $pgpdata
- The PGP data block.
- $email
- An e-mail address.
Returns
array An array with information on the PGP data block. If an
element is not present in the data block, it will
likewise not be set in the array.
Array Fields:
-------------
key_created => Key creation - UNIX timestamp
key_expires => Key expiration - UNIX timestamp (0 = never expires)
key_size => Size of the key in bits
key_type => The key type (public_key or secret_key)
name => Full Name
comment => Comment
email => E-mail Address
keyid => 16-bit hex value
created => Signature creation - UNIX timestamp
micalg => The hash used to create the signature
Throws
|
public
array
|
#
pgpPacketSignatureByUidIndex( string $pgpdata, string $uid_idx )
Returns information on a PGP signature embedded in PGP data. Similar
to pgpPacketSignature(), but returns information by unique User ID
Index (format id{n} where n is an integer of 1 or greater).
Returns information on a PGP signature embedded in PGP data. Similar
to pgpPacketSignature(), but returns information by unique User ID
Index (format id{n} where n is an integer of 1 or greater).
Parameters
- $pgpdata
- See pgpPacketSignature().
- $uid_idx
- The UID index.
Returns
array See pgpPacketSignature().
Throws
|
public
string
|
#
getSignersKeyID( string $text )
Returns the key ID of the key used to sign a block of PGP data.
Returns the key ID of the key used to sign a block of PGP data.
Parameters
- $text
- The PGP signed text block.
Returns
string The key ID of the key used to sign $text.
Throws
|
public
boolean
|
#
verifyPassphrase( string $public_key, string $private_key, string $passphrase )
Verify a passphrase for a given public/private keypair.
Verify a passphrase for a given public/private keypair.
Parameters
- $public_key
- The user's PGP public key.
- $private_key
- The user's PGP private key.
- $passphrase
- The user's passphrase.
Returns
boolean Returns true on valid passphrase, false on invalid
passphrase.
Throws
|
public
array
|
#
parsePGPData( string $text )
Parses a message into text and PGP components.
Parses a message into text and PGP components.
Parameters
Returns
array An array with the parsed text, returned in blocks of
text corresponding to their actual order. Keys:
'type' - (integer) The type of data contained in block.
Valid types are defined at the top of this class
(the ARMOR_* constants).
'data' - (array) The data for each section. Each line has been stripped
of EOL characters.
|
public
string
|
#
getPublicKeyserver( string $keyid, string $server = Horde_Crypt_Pgp::KEYSERVER_PUBLIC , float $timeout = Horde_Crypt_Pgp::KEYSERVER_TIMEOUT , string $address = null )
Returns a PGP public key from a public keyserver.
Returns a PGP public key from a public keyserver.
Parameters
- $keyid
- The key ID of the PGP key.
- $server
- The keyserver to use.
- $timeout
- The keyserver timeout.
- $address
- The email address of the PGP key.
Returns
string The PGP public key.
Throws
|
public
|
|
public
string
|
#
getKeyID( string $address, string $server = Horde_Crypt_Pgp::KEYSERVER_PUBLIC , float $timeout = Horde_Crypt_Pgp::KEYSERVER_TIMEOUT )
Returns the first matching key ID for an email address from a
public keyserver.
Returns the first matching key ID for an email address from a
public keyserver.
Parameters
- $address
- The email address of the PGP key.
- $server
- The keyserver to use.
- $timeout
- The keyserver timeout.
Returns
string The PGP key ID.
Throws
|
public
array
|
#
getFingerprintsFromKey( string $pgpdata )
Get the fingerprints from a key block.
Get the fingerprints from a key block.
Parameters
- $pgpdata
- The PGP data block.
Returns
array The fingerprints in $pgpdata indexed by key id.
Throws
|
public
string
|
#
encrypt( string $text, array $params = array() )
Encrypts text using PGP.
Parameters
- $text
- The text to be PGP encrypted.
- $params
- <p>The parameters needed for encryption.
See the individual _encrypt*() functions for the
parameter requirements.</p>
Returns
string The encrypted message.
Throws
Overrides
|
public
stdClass
|
#
decrypt( string $text, array $params = array() )
Decrypts text using PGP.
Parameters
- $text
- The text to be PGP decrypted.
- $params
- <p>The parameters needed for decryption.
See the individual _decrypt*() functions for the
parameter requirements.</p>
Returns
stdClass An object with the following properties:
'message' - (string) The signature result text.
'result' - (boolean) The result of the signature test.
Throws
Overrides
|
public
boolean
|
#
encryptedSymmetrically( string $text )
Returns whether a text has been encrypted symmetrically.
Returns whether a text has been encrypted symmetrically.
Parameters
- $text
- The PGP encrypted text.
Returns
boolean True if the text is symmetricallly encrypted.
Throws
|
public
mixed
|
#
signMIMEPart( Horde_Mime_Part $mime_part, array $params = array() )
Signs a MIME part using PGP.
Signs a MIME part using PGP.
Parameters
- $mime_part
- The object to sign.
- $params
- The parameters required for signing.
Returns
mixed A Horde_Mime_Part object that is signed according to RFC
3156.
Throws
See
_encryptSignature().
|
public
mixed
|
#
encryptMIMEPart( Horde_Mime_Part $mime_part, array $params = array() )
Encrypts a MIME part using PGP.
Encrypts a MIME part using PGP.
Parameters
- $mime_part
- The object to encrypt.
- $params
- <p>The parameters required for
encryption.</p>
Returns
mixed A Horde_Mime_Part object that is encrypted according to
RFC 3156.
Throws
See
_encryptMessage().
|
public
mixed
|
#
signAndEncryptMIMEPart( Horde_Mime_Part $mime_part, array $sign_params = array(), array $encrypt_params = array() )
Signs and encrypts a MIME part using PGP.
Signs and encrypts a MIME part using PGP.
Parameters
- $mime_part
- The object to sign and encrypt.
- $sign_params
- <p>The parameters required for
signing. @see _encryptSignature().</p>
- $encrypt_params
- <p>The parameters required for
encryption. @see _encryptMessage().</p>
Returns
mixed A Horde_Mime_Part object that is signed and encrypted
according to RFC 3156.
Throws
|
public
Horde_Mime_Part
|
#
publicKeyMIMEPart( string $key )
Generates a Horde_Mime_Part object, in accordance with RFC 3156, that
contains a public key.
Generates a Horde_Mime_Part object, in accordance with RFC 3156, that
contains a public key.
Parameters
Returns
Horde_Mime_Part An object that contains the public key.
|
public
string
|
#
generateRevocation( string $key, string $email, string $passphrase )
Generates a revocation certificate.
Generates a revocation certificate.
Parameters
- $key
- The private key.
- $email
- The email to use for the key.
- $passphrase
- The passphrase to use for the key.
Returns
string The revocation certificate.
Throws
|