Requires ext-mcrypt.

Taken from http://pl1.php.net/manual/en/function.mcrypt-encrypt.php#78531 and slightly adjusted, so credit goes to dylan at wedefy dot com.

Usage:

 $cipher = new \MD\Foundation\Crypto\Cipher('thisismysecret');
 $message = $cipher->encrypt('Hide from NSA... not really...');
 echo $message;
 // -> 'LEm/lBP+IVPlLvKQbUOlTkNAG34EwXH+mwqp4QCdOxQ='

 echo $cipher->decrypt($message);
 // -> 'Hide from NSA... not really...'

Methods This class defines the following methods:

__construct (string $secret, string $algorithm = MCRYPT_RIJNDAEL_256)

Constructor.

Arguments:
string $secret

Secret key to use in this cipher.

string $algorithm

[optional] Encryption algorithm. Preferably one of MCRYPT_{ciphername} constants or a string with the name of the algorithm. Default: MCRYPT_RIJNDAEL_256.

encrypt (string $input) -> string

Encrypt a string.

The secret and the algorithm passed to the constructor will be used for the encryption.

Example:

 $cipher = new \MD\Foundation\Crypto\Cipher('thisismysecret');
 $message = $cipher->encrypt('Hide from NSA... not really...');
 echo $message;
 // -> 'LEm/lBP+IVPlLvKQbUOlTkNAG34EwXH+mwqp4QCdOxQ='
Arguments:
string $input

String to be encrypted.

Returns:
string

decrypt (string $input) -> string

Decrypt an encrypted string.

The encrypted string must be encrypted with the same parameters (secret and algorithm) as the instantiated Cipher object.

Example:

 $cipher = new \MD\Foundation\Crypto\Cipher('thisismysecret');
 echo $cipher->decrypt('LEm/lBP+IVPlLvKQbUOlTkNAG34EwXH+mwqp4QCdOxQ=');
 // -> 'Hide from NSA... not really...'
Arguments:
string $input

Previously encrypted string to be decrypted.

Returns:
string