Skip to content

CI_Encryption

Mathieu Nayrolles edited this page Jan 20, 2016 · 1 revision

CI_Encryption

CodeIgniter Encryption Class

Provides two-way keyed encryption via PHP's MCrypt and/or OpenSSL extensions.

  • Class name: CI_Encryption
  • Namespace:

Properties

$_cipher

protected string $_cipher = 'aes-128'

Encryption cipher

  • Visibility: protected

$_mode

protected string $_mode = 'cbc'

Cipher mode

  • Visibility: protected

$_handle

protected mixed $_handle

Cipher handle

  • Visibility: protected

$_key

protected string $_key

Encryption key

  • Visibility: protected

$_driver

protected string $_driver

PHP extension to be used

  • Visibility: protected

$_drivers

protected array $_drivers = array()

List of usable drivers (PHP extensions)

  • Visibility: protected

$_modes

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

$_digests

protected array $_digests = array('sha224' => 28, 'sha256' => 32, 'sha384' => 48, 'sha512' => 64)

List of supported HMAC algorithms

name => digest size pairs

  • Visibility: protected

$func_override

protected boolean $func_override

mbstring.func_override flag

  • Visibility: protected
  • This property is static.

Methods

__construct

void CI_Encryption::__construct(array $params)

Class constructor

  • Visibility: public

Arguments

  • $params array - <p>Configuration parameters</p>

initialize

\CI_Encryption CI_Encryption::initialize(array $params)

Initialize

  • Visibility: public

Arguments

  • $params array - <p>Configuration parameters</p>

_mcrypt_initialize

void CI_Encryption::_mcrypt_initialize(array $params)

Initialize MCrypt

  • Visibility: protected

Arguments

  • $params array - <p>Configuration parameters</p>

_openssl_initialize

void CI_Encryption::_openssl_initialize(array $params)

Initialize OpenSSL

  • Visibility: protected

Arguments

  • $params array - <p>Configuration parameters</p>

create_key

string CI_Encryption::create_key(integer $length)

Create a random key

  • Visibility: public

Arguments

  • $length integer - <p>Output length</p>

encrypt

string CI_Encryption::encrypt(string $data, array $params)

Encrypt

  • Visibility: public

Arguments

  • $data string - <p>Input data</p>
  • $params array - <p>Input parameters</p>

_mcrypt_encrypt

string CI_Encryption::_mcrypt_encrypt(string $data, array $params)

Encrypt via MCrypt

  • Visibility: protected

Arguments

  • $data string - <p>Input data</p>
  • $params array - <p>Input parameters</p>

_openssl_encrypt

string CI_Encryption::_openssl_encrypt(string $data, array $params)

Encrypt via OpenSSL

  • Visibility: protected

Arguments

  • $data string - <p>Input data</p>
  • $params array - <p>Input parameters</p>

decrypt

string CI_Encryption::decrypt(string $data, array $params)

Decrypt

  • Visibility: public

Arguments

  • $data string - <p>Encrypted data</p>
  • $params array - <p>Input parameters</p>

_mcrypt_decrypt

string CI_Encryption::_mcrypt_decrypt(string $data, array $params)

Decrypt via MCrypt

  • Visibility: protected

Arguments

  • $data string - <p>Encrypted data</p>
  • $params array - <p>Input parameters</p>

_openssl_decrypt

string CI_Encryption::_openssl_decrypt(string $data, array $params)

Decrypt via OpenSSL

  • Visibility: protected

Arguments

  • $data string - <p>Encrypted data</p>
  • $params array - <p>Input parameters</p>

_get_params

array CI_Encryption::_get_params(array $params)

Get params

  • Visibility: protected

Arguments

  • $params array - <p>Input parameters</p>

_mcrypt_get_handle

resource CI_Encryption::_mcrypt_get_handle(string $cipher, string $mode)

Get MCrypt handle

  • Visibility: protected

Arguments

  • $cipher string - <p>Cipher name</p>
  • $mode string - <p>Encryption mode</p>

_openssl_get_handle

string CI_Encryption::_openssl_get_handle(string $cipher, string $mode)

Get OpenSSL handle

  • Visibility: protected

Arguments

  • $cipher string - <p>Cipher name</p>
  • $mode string - <p>Encryption mode</p>

_cipher_alias

void CI_Encryption::_cipher_alias(string $cipher)

Cipher alias

Tries to translate cipher names between MCrypt and OpenSSL's "dialects".

  • Visibility: protected

Arguments

  • $cipher string - <p>Cipher name</p>

hkdf

string CI_Encryption::hkdf($key, $digest, $salt, $length, $info)

HKDF

  • Visibility: public

Arguments

  • $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>

__get

mixed CI_Encryption::__get(string $key)

__get() magic

  • Visibility: public

Arguments

  • $key string - <p>Property name</p>

strlen

integer CI_Encryption::strlen(string $str)

Byte-safe strlen()

  • Visibility: protected
  • This method is static.

Arguments

  • $str string

substr

string CI_Encryption::substr(string $str, integer $start, integer $length)

Byte-safe substr()

  • Visibility: protected
  • This method is static.

Arguments

  • $str string
  • $start integer
  • $length integer
Clone this wiki locally