Symmetric encryption using the Mcrypt extension

NOTE: DO NOT USE only this class to encrypt data. This class doesn't provide authentication and integrity check over the data. PLEASE USE Zend\Crypt\BlockCipher instead!

package Default

 Methods

Constructor

__construct(array|\Traversable $options = array()

Parameters

$options

array\Traversable

Exceptions

\Zend\Crypt\Symmetric\Exception\RuntimeException
\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Decrypt

decrypt(string $data) : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::decrypt()

Parameters

$data

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

string

Encrypt

encrypt(string $data) : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::encrypt()

Parameters

$data

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

string

Get the encryption algorithm

getAlgorithm() : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getAlgorithm()

Returns

string

Get the block size

getBlockSize() : integer
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getBlockSize()

Returns

integer

Get the encryption key

getKey() : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getKey()

Returns

string

Get the maximum key size for the selected cipher and mode of operation

getKeySize() : integer
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getKeySize()

Returns

integer

Get the cipher mode

getMode() : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getMode()

Returns

string

Get the original salt value

getOriginalSalt() : string

Returns

string

Get the padding object

getPadding() : \Zend\Crypt\Symmetric\Padding\PaddingInterface

Returns

\Zend\Crypt\Symmetric\Padding\PaddingInterface

Returns the padding plugin manager. If it doesn't exist it's created.

getPaddingPluginManager() : \Zend\Crypt\Symmetric\PaddingPluginManager
Static

Returns

\Zend\Crypt\Symmetric\PaddingPluginManager

Get the salt (IV) according to the size requested by the algorithm

getSalt() : string
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getSalt()

Returns

string

Get the salt (IV) size

getSaltSize() : integer
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getSaltSize()

Returns

integer

Get the supported algorithms

getSupportedAlgorithms() : array
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getSupportedAlgorithms()

Returns

array

Get all supported encryption modes

getSupportedModes() : array
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::getSupportedModes()

Returns

array

Set the encryption algorithm (cipher)

setAlgorithm(string $algo) : \Zend\Crypt\Symmetric\Mcrypt
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::setAlgorithm()

Parameters

$algo

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

\Zend\Crypt\Symmetric\Mcrypt

Set the encryption key If the key is longer than maximum supported, it will be truncated by getKey().

setKey(string $key) : \Zend\Crypt\Symmetric\Mcrypt
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::setKey()

Parameters

$key

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

\Zend\Crypt\Symmetric\Mcrypt

Set the cipher mode

setMode(string $mode) : \Zend\Crypt\Symmetric\Mcrypt
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::setMode()

Parameters

$mode

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

\Zend\Crypt\Symmetric\Mcrypt

Set the padding object

setPadding(\Zend\Crypt\Symmetric\Padding\PaddingInterface $padding) : \Zend\Crypt\Symmetric\Mcrypt

Parameters

$padding

\Zend\Crypt\Symmetric\Padding\PaddingInterface

Returns

\Zend\Crypt\Symmetric\Mcrypt

Set the padding plugin manager

setPaddingPluginManager(string|\Zend\Crypt\Symmetric\PaddingPluginManager $plugins) : void
Static

Parameters

$plugins

string\Zend\Crypt\Symmetric\PaddingPluginManager

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Set the salt (IV)

setSalt(string $salt) : \Zend\Crypt\Symmetric\Mcrypt
inherited_from \Zend\Crypt\Symmetric\SymmetricInterface::setSalt()

Parameters

$salt

string

Exceptions

\Zend\Crypt\Symmetric\Exception\InvalidArgumentException

Returns

\Zend\Crypt\Symmetric\Mcrypt

Set default options

setDefaultOptions(array $options = array()) : void

Parameters

$options

array

 Properties

 

Encryption algorithm

$algo : string

Default

'aes'
 

IV

$iv : string

Default

 

Key

$key : string

Default

 

Encryption mode

$mode : string

Default

'cbc'
 

Padding

$padding : \Zend\Crypt\Symmetric\Padding\PaddingInterface

Default

 

Padding plugins

$paddingPlugins : \Zend\Crypt\Symmetric\PaddingPluginManager

Default

null
Static
 

Supported cipher algorithms

$supportedAlgos : array

Default

array('aes' => 'rijndael-128', 'blowfish' => 'blowfish', 'des' => 'des', '3des' => 'tripledes', 'tripledes' => 'tripledes', 'cast-128' => 'cast-128', 'cast-256' => 'cast-256', 'rijndael-128' => 'rijndael-128', 'rijndael-192' => 'rijndael-192', 'rijndael-256' => 'rijndael-256', 'saferplus' => 'saferplus', 'serpent' => 'serpent', 'twofish' => 'twofish')
 

Supported encryption modes

$supportedModes : array

Default

array('cbc' => 'cbc', 'cfb' => 'cfb', 'ctr' => 'ctr', 'ofb' => 'ofb', 'nofb' => 'nofb', 'ncfb' => 'ncfb')

 Constants

 

DEFAULT_PADDING

DEFAULT_PADDING = 'pkcs7'