Documentation

Horde_Crypt_Pgp extends Horde_Crypt
in package

A framework for Horde applications to interact with the GNU Privacy Guard program ("GnuPG"). GnuPG implements the OpenPGP standard (RFC 4880).

GnuPG Website: ()

Tags
author

Michael Slusarz slusarz@horde.org

author

Jan Schneider jan@horde.org

category

Horde

copyright

2002-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Table of Contents

ARMOR_MESSAGE  = 1
ARMOR_PRIVATE_KEY  = 4
ARMOR_PUBLIC_KEY  = 3
ARMOR_SIGNATURE  = 5
ARMOR_SIGNED_MESSAGE  = 2
ARMOR_TEXT  = 6
KEYSERVER_PUBLIC  = 'pool.sks-keyservers.net'
KEYSERVER_REFUSE  = 3
KEYSERVER_TIMEOUT  = 10
$_armor  : mixed
$_backends  : array<string|int, mixed>
List of initialized backends.
$_params  : array<string|int, mixed>
Configuration parameters.
__construct()  : mixed
Constructor.
decrypt()  : object
Decrypts text using PGP.
encrypt()  : string
Encrypts text using PGP.
encryptedSymmetrically()  : bool
Returns whether a text has been encrypted symmetrically.
encryptMIMEPart()  : mixed
Encrypts a MIME part using PGP.
factory()  : Horde_Crypt
Attempts to return a concrete Horde_Crypt instance based on $driver.
generateKey()  : array<string|int, mixed>
Generates a personal Public/Private keypair combination.
generateRevocation()  : mixed
getFingerprintsFromKey()  : array<string|int, mixed>
Get the fingerprints from a key block.
getKeyID()  : string
Returns the first matching key ID for an email address from a public keyserver.
getKeyIDString()  : mixed
TODO
getPublicKeyFromPrivateKey()  : string
Generates a public key from a private key.
getPublicKeyserver()  : mixed
getSignersKeyID()  : string
Returns the key ID of the key used to sign a block of PGP data.
parsePGPData()  : mixed
pgpPacketInformation()  : array<string|int, mixed>
Returns information on a PGP data block.
pgpPacketInformationMultiple()  : array<string|int, mixed>
Returns all information on a PGP data block.
pgpPacketSignature()  : array<string|int, mixed>
Returns only information on the first ID that matches the email address input.
pgpPacketSignatureByUidIndex()  : array<string|int, mixed>
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
Returns human readable information on a PGP key.
publicKeyMIMEPart()  : Horde_Mime_Part
Generates a Horde_Mime_Part object, in accordance with RFC 3156, that contains a public key.
putPublicKeyserver()  : mixed
Sends a PGP public key to a public keyserver.
signAndEncryptMIMEPart()  : mixed
Signs and encrypts a MIME part using PGP.
signMIMEPart()  : mixed
Signs a MIME part using PGP.
verifyPassphrase()  : bool
Verify a passphrase for a given public/private keypair.
_initDrivers()  : mixed
Initialize the backend driver list.
_pgpPacketSignature()  : array<string|int, mixed>
Adds some data to the pgpPacketSignature*() function array.

Constants

ARMOR_MESSAGE

public mixed ARMOR_MESSAGE = 1
Tags
deprecated

Use Horde_Crypt_Pgp_Parse instead.

ARMOR_PRIVATE_KEY

public mixed ARMOR_PRIVATE_KEY = 4

ARMOR_PUBLIC_KEY

public mixed ARMOR_PUBLIC_KEY = 3

ARMOR_SIGNATURE

public mixed ARMOR_SIGNATURE = 5

ARMOR_SIGNED_MESSAGE

public mixed ARMOR_SIGNED_MESSAGE = 2

ARMOR_TEXT

public mixed ARMOR_TEXT = 6

KEYSERVER_PUBLIC

public mixed KEYSERVER_PUBLIC = 'pool.sks-keyservers.net'
Tags
deprecated

Use Horde_Crypt_Pgp_Keyserver instead.

KEYSERVER_REFUSE

public mixed KEYSERVER_REFUSE = 3

KEYSERVER_TIMEOUT

public mixed KEYSERVER_TIMEOUT = 10

Properties

$_armor

protected mixed $_armor = array('MESSAGE' => self::ARMOR_MESSAGE, 'SIGNED MESSAGE' => self::ARMOR_SIGNED_MESSAGE, 'PUBLIC KEY BLOCK' => self::ARMOR_PUBLIC_KEY, 'PRIVATE KEY BLOCK' => self::ARMOR_PRIVATE_KEY, 'SIGNATURE' => self::ARMOR_SIGNATURE)
Tags
deprecated

Use Horde_Crypt_Pgp_Parse instead.

$_backends

List of initialized backends.

protected array<string|int, mixed> $_backends = array()

$_params

Configuration parameters.

protected array<string|int, mixed> $_params = array()

Methods

__construct()

Constructor.

public __construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
$params : array<string|int, mixed> = 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.
Return values
mixed

decrypt()

Decrypts text using PGP.

public decrypt(string $text[, array<string|int, mixed> $params = array() ]) : object
Parameters
$text : string

The text to be PGP decrypted.

$params : array<string|int, mixed> = array()

The parameters needed for decryption. See the individual _decrypt*() functions for the parameter requirements.

Tags
throws
Horde_Crypt_Exception
Return values
object

An object with the following properties:

  • message: (string) The signature result text.
  • result: (boolean) The result of the signature test.

encrypt()

Encrypts text using PGP.

public encrypt(string $text[, array<string|int, mixed> $params = array() ]) : string
Parameters
$text : string

The text to be PGP encrypted.

$params : array<string|int, mixed> = array()

The parameters needed for encryption. See the individual _encrypt*() functions for the parameter requirements.

Tags
throws
Horde_Crypt_Exception
Return values
string

The encrypted message.

encryptedSymmetrically()

Returns whether a text has been encrypted symmetrically.

public encryptedSymmetrically(string $text) : bool
Parameters
$text : string

The PGP encrypted text.

Tags
todo

Return null, instead of exception, if tools are not available to determine whether data was encrypted symmetrically.

throws
Horde_Crypt_Exception
Return values
bool

True if the text is symmetrically encrypted.

encryptMIMEPart()

Encrypts a MIME part using PGP.

public encryptMIMEPart(Horde_Mime_Part $mime_part[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$mime_part : Horde_Mime_Part

The object to encrypt.

$params : array<string|int, mixed> = array()

The parameters required for encryption (_encryptMessage()).

Tags
throws
Horde_Crypt_Exception
Return values
mixed

A Horde_Mime_Part object that is encrypted according to RFC 3156.

factory()

Attempts to return a concrete Horde_Crypt instance based on $driver.

public static factory(string $driver[, array<string|int, mixed> $params = array() ]) : Horde_Crypt
Parameters
$driver : string

Either a driver name, or the full class name to use (class must extend Horde_Crypt).

$params : array<string|int, mixed> = array()

A hash containing any additional configuration or parameters a subclass might need.

Tags
throws
Horde_Crypt_Exception
Return values
Horde_Crypt

The newly created concrete instance.

generateKey()

Generates a personal Public/Private keypair combination.

public generateKey(string $realname, string $email, string $passphrase[, string $comment = '' ][, int $keylength = 1024 ][, int $expire = null ][, string $key_type = 'RSA' ][, string $subkey_type = 'RSA' ]) : array<string|int, mixed>
Parameters
$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 : int = 1024

The keylength to use for the key.

$expire : int = null

The expiration date (UNIX timestamp). No expiration if empty.

$key_type : string = 'RSA'

Key type (@since 2.2.0).

$subkey_type : string = 'RSA'

Subkey type (@since 2.2.0).

Tags
throws
Horde_Crypt_Exception
Return values
array<string|int, mixed>

An array consisting of the following keys/values:

  • private: (string) Private key.
  • public: (string) Public key.

generateRevocation()

public generateRevocation(mixed $key, mixed $email, mixed $passphrase) : mixed
Parameters
$key : mixed
$email : mixed
$passphrase : mixed
Tags
deprecated
Return values
mixed

getFingerprintsFromKey()

Get the fingerprints from a key block.

public getFingerprintsFromKey(string $pgpdata) : array<string|int, mixed>
Parameters
$pgpdata : string

The PGP data block.

Return values
array<string|int, mixed>

The fingerprints in $pgpdata indexed by key id.

getKeyID()

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
Parameters
$address : string

The email address of the PGP key.

$server : string = self::KEYSERVER_PUBLIC

The keyserver to use.

$timeout : float = self::KEYSERVER_TIMEOUT

The keyserver timeout.

Tags
throws
Horde_Crypt_Exception
Return values
string

The PGP key ID.

getKeyIDString()

TODO

public getKeyIDString(mixed $keyid) : mixed
Parameters
$keyid : mixed
Tags
since
2.4.0
Return values
mixed

getPublicKeyFromPrivateKey()

Generates a public key from a private key.

public getPublicKeyFromPrivateKey(string $data) : string
Parameters
$data : string

Armor text of private key.

Return values
string

Armor text of public key, or null if it could not be generated.

getPublicKeyserver()

public getPublicKeyserver(mixed $keyid[, mixed $server = self::KEYSERVER_PUBLIC ][, mixed $timeout = self::KEYSERVER_TIMEOUT ][, mixed $address = null ]) : mixed
Parameters
$keyid : mixed
$server : mixed = self::KEYSERVER_PUBLIC
$timeout : mixed = self::KEYSERVER_TIMEOUT
$address : mixed = null
Tags
deprecated

Use Horde_Crypt_Pgp_Keyserver instead.

Return values
mixed

getSignersKeyID()

Returns the key ID of the key used to sign a block of PGP data.

public getSignersKeyID(string $text) : string
Parameters
$text : string

The PGP signed text block.

Return values
string

The key ID of the key used to sign $text, or null if not found.

parsePGPData()

public parsePGPData(mixed $text) : mixed
Parameters
$text : mixed
Tags
deprecated

Use Horde_Crypt_Pgp_Parse instead.

Return values
mixed

pgpPacketInformation()

Returns information on a PGP data block.

public pgpPacketInformation(string $pgpdata) : array<string|int, mixed>

If the data block contains multiple keys, only the first is returned. To return all keys of this block, use pgpPacketInformationMultiple() instead.

Parameters
$pgpdata : string

The PGP data block.

Tags
see
pgpPacketInformationMultiple()
Return values
array<string|int, mixed>

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

Returns all information on a PGP data block.

public pgpPacketInformationMultiple(string $pgpdata) : array<string|int, mixed>
Parameters
$pgpdata : string

The PGP data block.

Tags
since

Horde_Crypt 2.7.0

see
pgpPacketInformation()
Return values
array<string|int, mixed>

An array with information on the PGP data block. The array contains one or more entries as returned from pgpPacketInformation().

pgpPacketSignature()

Returns only information on the first ID that matches the email address input.

public pgpPacketSignature(string $pgpdata, string $email) : array<string|int, mixed>
Parameters
$pgpdata : string

The PGP data block.

$email : string

An e-mail address.

Return values
array<string|int, mixed>

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

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

public pgpPacketSignatureByUidIndex(string $pgpdata, string $uid_idx) : array<string|int, mixed>
Parameters
$pgpdata : string

See pgpPacketSignature().

$uid_idx : string

The UID index.

Tags
see
pgpPacketSignature()
Return values
array<string|int, mixed>

See pgpPacketSignature().

pgpPrettyKey()

Returns human readable information on a PGP key.

public pgpPrettyKey(string $pgpdata) : string
Parameters
$pgpdata : string

The PGP data block.

Tags
throws
Horde_Crypt_Exception
Return values
string

Tabular information on the PGP key.

publicKeyMIMEPart()

Generates a Horde_Mime_Part object, in accordance with RFC 3156, that contains a public key.

public publicKeyMIMEPart(string $key) : Horde_Mime_Part
Parameters
$key : string

The public key.

Return values
Horde_Mime_Part

An object that contains the public key.

putPublicKeyserver()

Sends a PGP public key to a public keyserver.

public putPublicKeyserver(string $pubkey[, string $server = self::KEYSERVER_PUBLIC ][, float $timeout = self::KEYSERVER_TIMEOUT ]) : mixed
Parameters
$pubkey : string

The PGP public key

$server : string = self::KEYSERVER_PUBLIC

The keyserver to use.

$timeout : float = self::KEYSERVER_TIMEOUT

The keyserver timeout.

Tags
throws
Horde_Crypt_Exception
Return values
mixed

signAndEncryptMIMEPart()

Signs and encrypts a MIME part using PGP.

public signAndEncryptMIMEPart(Horde_Mime_Part $mime_part[, array<string|int, mixed> $sign_params = array() ][, array<string|int, mixed> $encrypt_params = array() ]) : mixed
Parameters
$mime_part : Horde_Mime_Part

The object to sign and encrypt.

$sign_params : array<string|int, mixed> = array()

The parameters required for signing (_encryptSignature()).

$encrypt_params : array<string|int, mixed> = array()

The parameters required for encryption (_encryptMessage()).

Tags
throws
Horde_Crypt_Exception
Return values
mixed

A Horde_Mime_Part object that is signed and encrypted according to RFC 3156.

signMIMEPart()

Signs a MIME part using PGP.

public signMIMEPart(Horde_Mime_Part $mime_part[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$mime_part : Horde_Mime_Part

The object to sign.

$params : array<string|int, mixed> = array()

The parameters required for signing. (_encryptSignature()).

Tags
throws
Horde_Crypt_Exception
Return values
mixed

A Horde_Mime_Part object that is signed according to RFC 3156.

verifyPassphrase()

Verify a passphrase for a given public/private keypair.

public verifyPassphrase(string $public_key, string $private_key, string $passphrase) : bool
Parameters
$public_key : string

The user's PGP public key.

$private_key : string

The user's PGP private key.

$passphrase : string

The user's passphrase.

Tags
throws
Horde_Crypt_Exception
Return values
bool

Returns true on valid passphrase, false on invalid passphrase.

_initDrivers()

Initialize the backend driver list.

protected _initDrivers() : mixed
Return values
mixed

_pgpPacketSignature()

Adds some data to the pgpPacketSignature*() function array.

protected _pgpPacketSignature(array<string|int, mixed> $data, array<string|int, mixed> $out) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

See pgpPacketSignature().

$out : array<string|int, mixed>

The return array.

Tags
see

pgpPacketSignature().

Return values
array<string|int, mixed>

The return array.

Search results