Horde_Crypt_Smime
extends Horde_Crypt
in package
Library to interact with the OpenSSL library and implement S/MIME.
Tags
Table of Contents
- $_params : array<string|int, mixed>
- Configuration parameters.
- __construct() : mixed
- Constructor.
- certToHTML() : string
- Convert a PEM format certificate to readable HTML version.
- checkForOpenSSL() : mixed
- Check for the presence of the OpenSSL extension to PHP.
- decrypt() : string
- Decrypt text via S/MIME.
- encrypt() : string
- Encrypt text using S/MIME.
- encryptMIMEPart() : Horde_Mime_Part
- Encrypt a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.3]).
- extractSignedContents() : string
- Extract the contents from signed S/MIME data.
- factory() : Horde_Crypt
- Attempts to return a concrete Horde_Crypt instance based on $driver.
- getEmailFromKey() : mixed
- Extract the email address from a public key.
- parseCert() : array<string|int, mixed>
- Extract the contents of a PEM format certificate to an array.
- parsePKCS12Data() : stdClass
- Convert a PKCS 12 encrypted certificate package into a private key, public key, and any additional keys.
- signAndEncryptMIMEPart() : mixed
- Sign and Encrypt a MIME part using S/MIME.
- signMIMEPart() : Horde_Mime_Part
- Sign a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.4]).
- verify() : stdClass
- Verify a signature using via S/MIME.
- verifyPassphrase() : bool
- Verify a passphrase for a given private key.
- _createTempFile() : string
- Create a temporary file that will be deleted at the end of this process.
- _decryptMessage() : string
- Decrypt an S/MIME encrypted message using a private/public keypair and a passhprase.
- _decryptSignature() : string
- Decrypt an S/MIME signed message using a public key.
- _encryptMessage() : string
- Encrypt a message in S/MIME format using a public key.
- _encryptSignature() : string
- Sign a message in S/MIME format using a private key.
- _fixContentType() : string
- The Content-Type parameters PHP's openssl_pkcs7_* functions return are deprecated. Fix these headers to the correct ones (see RFC 2311).
- _implodeValues() : string
- Formats a multi-value cert field.
Properties
$_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:
- temp: (string) Location of temporary directory.
Return values
mixed —certToHTML()
Convert a PEM format certificate to readable HTML version.
public
certToHTML(string $cert) : string
Parameters
- $cert : string
-
PEM format certificate.
Return values
string —HTML detailing the certificate.
checkForOpenSSL()
Check for the presence of the OpenSSL extension to PHP.
public
checkForOpenSSL() : mixed
Tags
Return values
mixed —decrypt()
Decrypt text via S/MIME.
public
decrypt(string $text[, array<string|int, mixed> $params = array() ]) : string
Parameters
- $text : string
-
The text to be smime decrypted.
- $params : array<string|int, mixed> = array()
-
The parameters needed for decryption. See the individual _decrypt*() functions for the parameter requirements.
Tags
Return values
string —The decrypted message.
encrypt()
Encrypt text using S/MIME.
public
encrypt(string $text[, array<string|int, mixed> $params = array() ]) : string
Parameters
- $text : string
-
The text to be encrypted.
- $params : array<string|int, mixed> = array()
-
The parameters needed for encryption. See the individual _encrypt*() functions for the parameter requirements.
Tags
Return values
string —The encrypted message.
encryptMIMEPart()
Encrypt a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.3]).
public
encryptMIMEPart(Horde_Mime_Part $mime_part[, array<string|int, mixed> $params = array() ]) : Horde_Mime_Part
Parameters
- $mime_part : Horde_Mime_Part
-
The object to encrypt.
- $params : array<string|int, mixed> = array()
-
The parameters required for encryption.
Tags
Return values
Horde_Mime_Part —An encrypted MIME part object.
extractSignedContents()
Extract the contents from signed S/MIME data.
public
extractSignedContents(string $data[, string $sslpath = null ]) : string
Parameters
- $data : string
-
The signed S/MIME data.
- $sslpath : string = null
-
The path to the OpenSSL binary. @deprecated and not used, just for backwards-compatibility.
Tags
Return values
string —The contents embedded in the signed data.
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
Return values
Horde_Crypt —The newly created concrete instance.
getEmailFromKey()
Extract the email address from a public key.
public
getEmailFromKey(string $key) : mixed
Parameters
- $key : string
-
The public key.
Return values
mixed —Returns the first email address found, or null if there are none.
parseCert()
Extract the contents of a PEM format certificate to an array.
public
parseCert(string $cert) : array<string|int, mixed>
Parameters
- $cert : string
-
PEM format certificate.
Return values
array<string|int, mixed> —All extractable information about the certificate.
parsePKCS12Data()
Convert a PKCS 12 encrypted certificate package into a private key, public key, and any additional keys.
public
parsePKCS12Data(string $pkcs12, array<string|int, mixed> $params) : stdClass
Parameters
- $pkcs12 : string
-
The PKCS 12 data.
- $params : array<string|int, mixed>
-
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)
Tags
Return values
stdClass —An object. 'private' - The private key in PEM format. 'public' - The public key in PEM format. 'certs' - An array of additional certs.
signAndEncryptMIMEPart()
Sign and Encrypt a MIME part using S/MIME.
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. @see _encryptSignature().
- $encrypt_params : array<string|int, mixed> = array()
-
The parameters required for encryption. @see _encryptMessage().
Tags
Return values
mixed —A Horde_Mime_Part object that is signed and encrypted.
signMIMEPart()
Sign a MIME part using S/MIME. This produces S/MIME Version 3.2 compatible data (see RFC 5751 [3.4]).
public
signMIMEPart(Horde_Mime_Part $mime_part, array<string|int, mixed> $params) : Horde_Mime_Part
Parameters
- $mime_part : Horde_Mime_Part
-
The object to sign.
- $params : array<string|int, mixed>
-
The parameters required for signing.
Tags
Return values
Horde_Mime_Part —A signed MIME part object.
verify()
Verify a signature using via S/MIME.
public
verify(string $text, mixed $certs) : stdClass
Parameters
- $text : string
-
The multipart/signed data to be verified.
- $certs : mixed
-
Either a single or array of root certificates.
Tags
Return values
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.
verifyPassphrase()
Verify a passphrase for a given private key.
public
verifyPassphrase(string $private_key, string $passphrase) : bool
Parameters
- $private_key : string
-
The user's private key.
- $passphrase : string
-
The user's passphrase.
Return values
bool —Returns true on valid passphrase, false on invalid passphrase.
_createTempFile()
Create a temporary file that will be deleted at the end of this process.
protected
_createTempFile([string $descrip = 'horde-crypt' ][, bool $delete = true ]) : string
Parameters
- $descrip : string = 'horde-crypt'
-
Description string to use in filename.
- $delete : bool = true
-
Delete the file automatically?
Return values
string —Filename of a temporary file.
_decryptMessage()
Decrypt an S/MIME encrypted message using a private/public keypair and a passhprase.
protected
_decryptMessage(string $text, array<string|int, mixed> $params) : string
Parameters
- $text : string
-
The text to be decrypted.
- $params : array<string|int, mixed>
-
The parameters needed for decryption.
Parameters: =========== 'type' => 'message' (REQUIRED) 'pubkey' => public key. (REQUIRED) 'privkey' => private key. (REQUIRED) 'passphrase' => Passphrase for Key. (REQUIRED)
Tags
Return values
string —The decrypted message.
_decryptSignature()
Decrypt an S/MIME signed message using a public key.
protected
_decryptSignature(string $text, array<string|int, mixed> $params) : string
Parameters
- $text : string
-
The text to be verified.
- $params : array<string|int, mixed>
-
The parameters needed for verification.
Tags
Return values
string —The verification message.
_encryptMessage()
Encrypt a message in S/MIME format using a public key.
protected
_encryptMessage(string $text, array<string|int, mixed> $params) : string
Parameters
- $text : string
-
The text to be encrypted.
- $params : array<string|int, mixed>
-
The parameters needed for encryption.
- type: (string) [REQUIRED] 'message'.
- pubkey: (mixed) [REQUIRED] Public key/cert or array of public keys/certs.
Tags
Return values
string —The encrypted message.
_encryptSignature()
Sign a message in S/MIME format using a private key.
protected
_encryptSignature(string $text, array<string|int, mixed> $params) : string
Parameters
- $text : string
-
The text to be signed.
- $params : array<string|int, mixed>
-
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)
Tags
Return values
string —The signed message.
_fixContentType()
The Content-Type parameters PHP's openssl_pkcs7_* functions return are deprecated. Fix these headers to the correct ones (see RFC 2311).
protected
_fixContentType(string $text, string $type) : string
Parameters
- $text : string
-
The PKCS7 data.
- $type : string
-
Is this 'message' or 'signature' data?
Return values
string —The PKCS7 data with the correct Content-Type parameter.
_implodeValues()
Formats a multi-value cert field.
protected
_implodeValues(array<string|int, mixed>|string $values) : string
Parameters
- $values : array<string|int, mixed>|string
-
A cert field value.
Return values
string —The formatted cert field value(s).