PHP Class Horde_Crypt_Pgp, horde

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.
Author: Michael Slusarz ([email protected])
Inheritance: extends Horde_Crypt
Show file Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_armor
$_backends array List of initialized backends.

Public Methods

Method Description
__construct ( array $params = [] ) Constructor.
decrypt ( string $text, array $params = [] ) : object Decrypts text using PGP.
encrypt ( string $text, array $params = [] ) : string Encrypts text using PGP.
encryptMIMEPart ( Horde_Mime_Part $mime_part, array $params = [] ) : mixed Encrypts a MIME part using PGP.
encryptedSymmetrically ( string $text ) : boolean Returns whether a text has been encrypted symmetrically.
generateKey ( string $realname, string $email, string $passphrase, string $comment = '', integer $keylength = 1024, integer $expire = null, string $key_type = 'RSA', string $subkey_type = 'RSA' ) : array Generates a personal Public/Private keypair combination.
generateRevocation ( $key, $email, $passphrase )
getFingerprintsFromKey ( string $pgpdata ) : array Get the fingerprints from a key block.
getKeyID ( string $address, string $server = self::KEYSERVER_PUBLIC, float $timeout = self::KEYSERVER_TIMEOUT ) : string Returns the first matching key ID for an email address from a public keyserver.
getKeyIDString ( $keyid ) TODO
getPublicKeyFromPrivateKey ( string $data ) : string Generates a public key from a private key.
getPublicKeyserver ( $keyid, $server = self::KEYSERVER_PUBLIC, $timeout = self::KEYSERVER_TIMEOUT, $address = null )
getSignersKeyID ( string $text ) : string Returns the key ID of the key used to sign a block of PGP data.
parsePGPData ( $text )
pgpPacketInformation ( string $pgpdata ) : array Returns information on a PGP data block.
pgpPacketInformationMultiple ( string $pgpdata ) : array Returns all information on a PGP data block.
pgpPacketSignature ( string $pgpdata, string $email ) : array Returns only information on the first ID that matches the email address input.
pgpPacketSignatureByUidIndex ( string $pgpdata, string $uid_idx ) : array 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).
pgpPrettyKey ( string $pgpdata ) : string Returns human readable information on a PGP key.
publicKeyMIMEPart ( string $key ) : Horde_Mime_Part Generates a Horde_Mime_Part object, in accordance with RFC 3156, that contains a public key.
putPublicKeyserver ( string $pubkey, string $server = self::KEYSERVER_PUBLIC, float $timeout = self::KEYSERVER_TIMEOUT ) Sends a PGP public key to a public keyserver.
signAndEncryptMIMEPart ( Horde_Mime_Part $mime_part, array $sign_params = [], array $encrypt_params = [] ) : mixed Signs and encrypts a MIME part using PGP.
signMIMEPart ( Horde_Mime_Part $mime_part, array $params = [] ) : mixed Signs a MIME part using PGP.
verifyPassphrase ( string $public_key, string $private_key, string $passphrase ) : boolean Verify a passphrase for a given public/private keypair.

Protected Methods

Method Description
_getKeyserverOb ( $server )
_initDrivers ( ) Initialize the backend driver list.
_pgpPacketSignature ( array $data, array $out ) : array Adds some data to the pgpPacketSignature*() function array.

Method Details

__construct() public method

Constructor.
public __construct ( array $params = [] )
$params array Configuration parameters: - backends: (array) The explicit list of backend drivers (Horde_Crypt_Pgp_Backend objects) to use. - program: (string) The path to the GnuPG binary. - temp: (string) Location of temporary directory.

_getKeyserverOb() protected method

Deprecation:
protected _getKeyserverOb ( $server )

_initDrivers() protected method

Initialize the backend driver list.
protected _initDrivers ( )

_pgpPacketSignature() protected method

Adds some data to the pgpPacketSignature*() function array.
protected _pgpPacketSignature ( array $data, array $out ) : array
$data array See pgpPacketSignature().
$out array The return array.
return array The return array.

decrypt() public method

Decrypts text using PGP.
public decrypt ( string $text, array $params = [] ) : object
$text string The text to be PGP decrypted.
$params array The parameters needed for decryption. See the individual _decrypt*() functions for the parameter requirements.
return object An object with the following properties: - message: (string) The signature result text. - result: (boolean) The result of the signature test.

encrypt() public method

Encrypts text using PGP.
public encrypt ( string $text, array $params = [] ) : string
$text string The text to be PGP encrypted.
$params array The parameters needed for encryption. See the individual _encrypt*() functions for the parameter requirements.
return string The encrypted message.

encryptMIMEPart() public method

Encrypts a MIME part using PGP.
public encryptMIMEPart ( Horde_Mime_Part $mime_part, array $params = [] ) : mixed
$mime_part Horde_Mime_Part The object to encrypt.
$params array The parameters required for encryption ({@see \_encryptMessage()}).
return mixed A Horde_Mime_Part object that is encrypted according to RFC 3156.

encryptedSymmetrically() public method

Returns whether a text has been encrypted symmetrically.
public encryptedSymmetrically ( string $text ) : boolean
$text string The PGP encrypted text.
return boolean True if the text is symmetrically encrypted.

generateKey() public method

Generates a personal Public/Private keypair combination.
public generateKey ( string $realname, string $email, string $passphrase, string $comment = '', integer $keylength = 1024, integer $expire = null, string $key_type = 'RSA', string $subkey_type = 'RSA' ) : array
$realname string The name to use for the key.
$email string The email to use for the key.
$passphrase string The passphrase to use for the key.
$comment string The comment to use for the key.
$keylength integer The keylength to use for the key.
$expire integer The expiration date (UNIX timestamp). No expiration if empty.
$key_type string Key type (@since 2.2.0).
$subkey_type string Subkey type (@since 2.2.0).
return array An array consisting of the following keys/values: - private: (string) Private key. - public: (string) Public key.

generateRevocation() public method

Deprecation:
public generateRevocation ( $key, $email, $passphrase )

getFingerprintsFromKey() public method

Get the fingerprints from a key block.
public getFingerprintsFromKey ( string $pgpdata ) : array
$pgpdata string The PGP data block.
return array The fingerprints in $pgpdata indexed by key id.

getKeyID() public method

Returns the first matching key ID for an email address from a public keyserver.
public getKeyID ( string $address, string $server = self::KEYSERVER_PUBLIC, float $timeout = self::KEYSERVER_TIMEOUT ) : string
$address string The email address of the PGP key.
$server string The keyserver to use.
$timeout float The keyserver timeout.
return string The PGP key ID.

getKeyIDString() public method

TODO
Since: 2.4.0
public getKeyIDString ( $keyid )

getPublicKeyFromPrivateKey() public method

Generates a public key from a private key.
public getPublicKeyFromPrivateKey ( string $data ) : string
$data string Armor text of private key.
return string Armor text of public key, or null if it could not be generated.

getPublicKeyserver() public method

Deprecation: Use Horde_Crypt_Pgp_Keyserver instead.
public getPublicKeyserver ( $keyid, $server = self::KEYSERVER_PUBLIC, $timeout = self::KEYSERVER_TIMEOUT, $address = null )

getSignersKeyID() public method

Returns the key ID of the key used to sign a block of PGP data.
public getSignersKeyID ( string $text ) : string
$text string The PGP signed text block.
return string The key ID of the key used to sign $text, or null if not found.

parsePGPData() public method

Deprecation: Use Horde_Crypt_Pgp_Parse instead.
public parsePGPData ( $text )

pgpPacketInformation() public method

If the data block contains multiple keys, only the first is returned. To return all keys of this block, use pgpPacketInformationMultiple() instead.
See also: pgpPacketInformationMultiple()
public pgpPacketInformation ( string $pgpdata ) : array
$pgpdata string The PGP data block.
return 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

[signature] => Array (
    [id{n}/'_SIGNATURE'] => Array (
        [name]        => Full Name
        [comment]     => Comment
        [email]       => E-mail Address
        [keyid]       => 16-bit hex value
        [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
            [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'.

pgpPacketInformationMultiple() public method

Returns all information on a PGP data block.
See also: pgpPacketInformation()
public pgpPacketInformationMultiple ( string $pgpdata ) : array
$pgpdata string The PGP data block.
return array An array with information on the PGP data block. The array contains one or more entries as returned from pgpPacketInformation().

pgpPacketSignature() public method

Returns only information on the first ID that matches the email address input.
public pgpPacketSignature ( string $pgpdata, string $email ) : array
$pgpdata string The PGP data block.
$email string An e-mail address.
return 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 elements: - comment: Comment - created: Signature creation (UNIX timestamp) - email: E-mail Address - 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) - keyid: 16-bit hex value - micalg: The hash used to create the signature - name: Full Name

pgpPacketSignatureByUidIndex() public method

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).
See also: pgpPacketSignature()
public pgpPacketSignatureByUidIndex ( string $pgpdata, string $uid_idx ) : array
$pgpdata string See pgpPacketSignature().
$uid_idx string The UID index.
return array See pgpPacketSignature().

pgpPrettyKey() public method

Returns human readable information on a PGP key.
public pgpPrettyKey ( string $pgpdata ) : string
$pgpdata string The PGP data block.
return string Tabular information on the PGP key.

publicKeyMIMEPart() public method

Generates a Horde_Mime_Part object, in accordance with RFC 3156, that contains a public key.
public publicKeyMIMEPart ( string $key ) : Horde_Mime_Part
$key string The public key.
return Horde_Mime_Part An object that contains the public key.

putPublicKeyserver() public method

Sends a PGP public key to a public keyserver.
public putPublicKeyserver ( string $pubkey, string $server = self::KEYSERVER_PUBLIC, float $timeout = self::KEYSERVER_TIMEOUT )
$pubkey string The PGP public key
$server string The keyserver to use.
$timeout float The keyserver timeout.

signAndEncryptMIMEPart() public method

Signs and encrypts a MIME part using PGP.
public signAndEncryptMIMEPart ( Horde_Mime_Part $mime_part, array $sign_params = [], array $encrypt_params = [] ) : mixed
$mime_part Horde_Mime_Part The object to sign and encrypt.
$sign_params array The parameters required for signing ({@see \_encryptSignature()}).
$encrypt_params array The parameters required for encryption ({@see \_encryptMessage()}).
return mixed A Horde_Mime_Part object that is signed and encrypted according to RFC 3156.

signMIMEPart() public method

Signs a MIME part using PGP.
public signMIMEPart ( Horde_Mime_Part $mime_part, array $params = [] ) : mixed
$mime_part Horde_Mime_Part The object to sign.
$params array The parameters required for signing. ({@see \_encryptSignature()}).
return mixed A Horde_Mime_Part object that is signed according to RFC 3156.

verifyPassphrase() public method

Verify a passphrase for a given public/private keypair.
public verifyPassphrase ( string $public_key, string $private_key, string $passphrase ) : boolean
$public_key string The user's PGP public key.
$private_key string The user's PGP private key.
$passphrase string The user's passphrase.
return boolean Returns true on valid passphrase, false on invalid passphrase.

Property Details

$_armor protected property

Deprecation: Use Horde_Crypt_Pgp_Parse instead.
protected $_armor

$_backends protected property

List of initialized backends.
protected array $_backends
return array