-
Notifications
You must be signed in to change notification settings - Fork 0
CI_Encryption
Mathieu Nayrolles edited this page Jan 20, 2016
·
1 revision
CodeIgniter Encryption Class
Provides two-way keyed encryption via PHP's MCrypt and/or OpenSSL extensions.
- Class name: CI_Encryption
- Namespace:
protected string $_cipher = 'aes-128'
Encryption cipher
- Visibility: protected
protected string $_mode = 'cbc'
Cipher mode
- Visibility: protected
protected mixed $_handle
Cipher handle
- Visibility: protected
protected string $_key
Encryption key
- Visibility: protected
protected string $_driver
PHP extension to be used
- Visibility: protected
protected array $_drivers = array()
List of usable drivers (PHP extensions)
- Visibility: protected
protected array $_modes = array('mcrypt' => array('cbc' => 'cbc', 'ecb' => 'ecb', 'ofb' => 'nofb', 'ofb8' => 'ofb', 'cfb' => 'ncfb', 'cfb8' => 'cfb', 'ctr' => 'ctr', 'stream' => 'stream'), 'openssl' => array('cbc' => 'cbc', 'ecb' => 'ecb', 'ofb' => 'ofb', 'cfb' => 'cfb', 'cfb8' => 'cfb8', 'ctr' => 'ctr', 'stream' => '', 'xts' => 'xts'))
List of available modes
- Visibility: protected
protected array $_digests = array('sha224' => 28, 'sha256' => 32, 'sha384' => 48, 'sha512' => 64)
List of supported HMAC algorithms
name => digest size pairs
- Visibility: protected
protected boolean $func_override
mbstring.func_override flag
- Visibility: protected
- This property is static.
void CI_Encryption::__construct(array $params)
Class constructor
- Visibility: public
- $params array - <p>Configuration parameters</p>
\CI_Encryption CI_Encryption::initialize(array $params)
Initialize
- Visibility: public
- $params array - <p>Configuration parameters</p>
void CI_Encryption::_mcrypt_initialize(array $params)
Initialize MCrypt
- Visibility: protected
- $params array - <p>Configuration parameters</p>
void CI_Encryption::_openssl_initialize(array $params)
Initialize OpenSSL
- Visibility: protected
- $params array - <p>Configuration parameters</p>
string CI_Encryption::create_key(integer $length)
Create a random key
- Visibility: public
- $length integer - <p>Output length</p>
string CI_Encryption::encrypt(string $data, array $params)
Encrypt
- Visibility: public
- $data string - <p>Input data</p>
- $params array - <p>Input parameters</p>
string CI_Encryption::_mcrypt_encrypt(string $data, array $params)
Encrypt via MCrypt
- Visibility: protected
- $data string - <p>Input data</p>
- $params array - <p>Input parameters</p>
string CI_Encryption::_openssl_encrypt(string $data, array $params)
Encrypt via OpenSSL
- Visibility: protected
- $data string - <p>Input data</p>
- $params array - <p>Input parameters</p>
string CI_Encryption::decrypt(string $data, array $params)
Decrypt
- Visibility: public
- $data string - <p>Encrypted data</p>
- $params array - <p>Input parameters</p>
string CI_Encryption::_mcrypt_decrypt(string $data, array $params)
Decrypt via MCrypt
- Visibility: protected
- $data string - <p>Encrypted data</p>
- $params array - <p>Input parameters</p>
string CI_Encryption::_openssl_decrypt(string $data, array $params)
Decrypt via OpenSSL
- Visibility: protected
- $data string - <p>Encrypted data</p>
- $params array - <p>Input parameters</p>
array CI_Encryption::_get_params(array $params)
Get params
- Visibility: protected
- $params array - <p>Input parameters</p>
resource CI_Encryption::_mcrypt_get_handle(string $cipher, string $mode)
Get MCrypt handle
- Visibility: protected
- $cipher string - <p>Cipher name</p>
- $mode string - <p>Encryption mode</p>
string CI_Encryption::_openssl_get_handle(string $cipher, string $mode)
Get OpenSSL handle
- Visibility: protected
- $cipher string - <p>Cipher name</p>
- $mode string - <p>Encryption mode</p>
void CI_Encryption::_cipher_alias(string $cipher)
Cipher alias
Tries to translate cipher names between MCrypt and OpenSSL's "dialects".
- Visibility: protected
- $cipher string - <p>Cipher name</p>
string CI_Encryption::hkdf($key, $digest, $salt, $length, $info)
HKDF
- Visibility: public
- $key mixed - <p>Input key</p>
- $digest mixed - <p>A SHA-2 hashing algorithm</p>
- $salt mixed - <p>Optional salt</p>
- $length mixed - <p>Output length (defaults to the selected digest size)</p>
- $info mixed - <p>Optional context/application-specific info</p>
mixed CI_Encryption::__get(string $key)
__get() magic
- Visibility: public
- $key string - <p>Property name</p>
integer CI_Encryption::strlen(string $str)
Byte-safe strlen()
- Visibility: protected
- This method is static.
- $str string
string CI_Encryption::substr(string $str, integer $start, integer $length)
Byte-safe substr()
- Visibility: protected
- This method is static.
- $str string
- $start integer
- $length integer