Properties

$_params

$_params : array

Configuration parameters.

Type

array

Methods

factory()

factory(string  $driver, array  $params = array()) : \Horde_Crypt

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

Parameters

string $driver

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

array $params

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

Throws

\Horde_Crypt_Exception

Returns

\Horde_Crypt

The newly created concrete instance.

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

Configuration parameters:

  • temp: (string) Location of temporary directory.

encrypt()

encrypt(string  $text, array  $params = array()) : string

Encrypt text using S/MIME.

This method should be provided by all classes that extend Horde_Crypt.

Parameters

string $text

The text to be encrypted.

array $params

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

Throws

\Horde_Crypt_Exception

Returns

string —

The encrypted message.

decrypt()

decrypt(string  $text, array  $params = array()) : string

Decrypt text via S/MIME.

This method should be provided by all classes that extend Horde_Crypt.

Parameters

string $text

The text to be smime decrypted.

array $params

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

Throws

\Horde_Crypt_Exception

Returns

string —

The decrypted message.

verifyPassphrase()

verifyPassphrase(string  $private_key, string  $passphrase) : boolean

Verify a passphrase for a given private key.

Parameters

string $private_key

The user's private key.

string $passphrase

The user's passphrase.

Returns

boolean —

Returns true on valid passphrase, false on invalid passphrase.

verify()

verify(string  $text, mixed  $certs) : \stdClass

Verify a signature using via S/MIME.

Parameters

string $text

The multipart/signed data to be verified.

mixed $certs

Either a single or array of root certificates.

Throws

\Horde_Crypt_Exception

Returns

\stdClass —

Object with the following elements:

cert - (string) The certificate of the signer stored in the message (in
       PEM format).
email - (string) The email of the signing person.
msg - (string) Status string.
verify - (boolean) True if certificate was verified.

extractSignedContents()

extractSignedContents(string  $data, string  $sslpath = null) : string

Extract the contents from signed S/MIME data.

Parameters

string $data

The signed S/MIME data.

string $sslpath

The path to the OpenSSL binary. @deprecated and not used, just for backwards-compatibility.

Throws

\Horde_Crypt_Exception

Returns

string —

The contents embedded in the signed data.

signMIMEPart()

signMIMEPart(\Horde_Mime_Part  $mime_part, array  $params) : \Horde_Mime_Part

Sign a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.4]).

Parameters

\Horde_Mime_Part $mime_part

The object to sign.

array $params

The parameters required for signing.

Throws

\Horde_Crypt_Exception

Returns

\Horde_Mime_Part —

A signed MIME part object.

encryptMIMEPart()

encryptMIMEPart(\Horde_Mime_Part  $mime_part, array  $params = array()) : \Horde_Mime_Part

Encrypt a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.3]).

Parameters

\Horde_Mime_Part $mime_part

The object to encrypt.

array $params

The parameters required for encryption.

Throws

\Horde_Crypt_Exception

Returns

\Horde_Mime_Part —

An encrypted MIME part object.

signAndEncryptMIMEPart()

signAndEncryptMIMEPart(\Horde_Mime_Part  $mime_part, array  $sign_params = array(), array  $encrypt_params = array()) : mixed

Sign and Encrypt a MIME part using S/MIME.

Parameters

\Horde_Mime_Part $mime_part

The object to sign and encrypt.

array $sign_params

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

array $encrypt_params

The parameters required for encryption. @see _encryptMessage().

Throws

\Horde_Crypt_Exception

Returns

mixed —

A Horde_Mime_Part object that is signed and encrypted.

certToHTML()

certToHTML(string  $cert) : string

Convert a PEM format certificate to readable HTML version.

Parameters

string $cert

PEM format certificate.

Returns

string —

HTML detailing the certificate.

parseCert()

parseCert(string  $cert) : array

Extract the contents of a PEM format certificate to an array.

Parameters

string $cert

PEM format certificate.

Returns

array —

All extractable information about the certificate.

checkForOpenSSL()

checkForOpenSSL() 

Check for the presence of the OpenSSL extension to PHP.

Throws

\Horde_Crypt_Exception

getEmailFromKey()

getEmailFromKey(string  $key) : mixed

Extract the email address from a public key.

Parameters

string $key

The public key.

Returns

mixed —

Returns the first email address found, or null if there are none.

parsePKCS12Data()

parsePKCS12Data(string  $pkcs12, array  $params) : \stdClass

Convert a PKCS 12 encrypted certificate package into a private key, public key, and any additional keys.

Parameters

string $pkcs12

The PKCS 12 data.

array $params

The parameters needed for parsing.

Parameters:
===========
'sslpath' => The path to the OpenSSL binary. (REQUIRED)
'password' => The password to use to decrypt the data. (Optional)
'newpassword' => The password to use to encrypt the private key.
                 (Optional)

Throws

\Horde_Crypt_Exception

Returns

\stdClass —

An object. 'private' - The private key in PEM format. 'public' - The public key in PEM format. 'certs' - An array of additional certs.

_encryptMessage()

_encryptMessage(string  $text, array  $params) : string

Encrypt a message in S/MIME format using a public key.

Parameters

string $text

The text to be encrypted.

array $params

The parameters needed for encryption.

  • type: (string) [REQUIRED] 'message'.
  • pubkey: (mixed) [REQUIRED] Public key/cert or array of public keys/certs.

Throws

\Horde_Crypt_Exception

Returns

string —

The encrypted message.

_encryptSignature()

_encryptSignature(string  $text, array  $params) : string

Sign a message in S/MIME format using a private key.

Parameters

string $text

The text to be signed.

array $params

The (string) parameters needed for signing:

  • 'certs': Additional signing certs (Optional)
  • 'passphrase': Passphrase for key (REQUIRED)
  • 'privkey': Private key (REQUIRED)
  • 'pubkey': Public key (REQUIRED)
  • 'sigtype': Determine the signature type to use. (Optional):
    • 'cleartext': Make a clear text signature
    • 'detach': Make a detached signature (DEFAULT)
  • 'type': 'signature' (REQUIRED)

Throws

\Horde_Crypt_Exception

Returns

string —

The signed message.

_decryptMessage()

_decryptMessage(string  $text, array  $params) : string

Decrypt an S/MIME encrypted message using a private/public keypair and a passhprase.

Parameters

string $text

The text to be decrypted.

array $params

The parameters needed for decryption.

Parameters:
===========
'type'        =>  'message' (REQUIRED)
'pubkey'      =>  public key. (REQUIRED)
'privkey'     =>  private key. (REQUIRED)
'passphrase'  =>  Passphrase for Key. (REQUIRED)

Throws

\Horde_Crypt_Exception

Returns

string —

The decrypted message.

_implodeValues()

_implodeValues(array|string  $values) : string

Formats a multi-value cert field.

Parameters

array|string $values

A cert field value.

Returns

string —

The formatted cert field value(s).

_decryptSignature()

_decryptSignature(string  $text, array  $params) : string

Decrypt an S/MIME signed message using a public key.

Parameters

string $text

The text to be verified.

array $params

The parameters needed for verification.

Throws

\Horde_Crypt_Exception

Returns

string —

The verification message.

_fixContentType()

_fixContentType(string  $text, string  $type) : string

The Content-Type parameters PHP's openssl_pkcs7_* functions return are deprecated. Fix these headers to the correct ones (see RFC 2311).

Parameters

string $text

The PKCS7 data.

string $type

Is this 'message' or 'signature' data?

Returns

string —

The PKCS7 data with the correct Content-Type parameter.

_createTempFile()

_createTempFile(string  $descrip = 'horde-crypt', boolean  $delete = true) : string

Create a temporary file that will be deleted at the end of this process.

Parameters

string $descrip

Description string to use in filename.

boolean $delete

Delete the file automatically?

Returns

string —

Filename of a temporary file.