PHP Class CI_Encryption, TastyIgniter

Provides two-way keyed encryption via PHP's MCrypt and/or OpenSSL extensions.
显示文件 Open project: tastyigniter/tastyigniter Class Usage Examples

Protected Properties

Property Type Description
$_cipher string Encryption cipher
$_digests array name => digest size pairs
$_driver string PHP extension to be used
$_drivers array List of usable drivers (PHP extensions)
$_handle mixed Cipher handle
$_key string Encryption key
$_mode string Cipher mode
$_modes array List of available modes
$func_override boolean mbstring.func_override flag

Public Methods

Method Description
__construct ( array $params = [] ) : void Class constructor
__get ( string $key ) : mixed __get() magic
create_key ( integer $length ) : string Create a random key
decrypt ( string $data, array $params = NULL ) : string Decrypt
encrypt ( string $data, array $params = NULL ) : string Encrypt
hkdf ( $key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '' ) : string HKDF
initialize ( array $params ) : CI_Encryption Initialize

Protected Methods

Method Description
_cipher_alias ( string &$cipher ) : void Cipher alias
_get_params ( array $params ) : array Get params
_mcrypt_decrypt ( string $data, array $params ) : string Decrypt via MCrypt
_mcrypt_encrypt ( string $data, array $params ) : string Encrypt via MCrypt
_mcrypt_get_handle ( string $cipher, string $mode ) : resource Get MCrypt handle
_mcrypt_initialize ( array $params ) : void Initialize MCrypt
_openssl_decrypt ( string $data, array $params ) : string Decrypt via OpenSSL
_openssl_encrypt ( string $data, array $params ) : string Encrypt via OpenSSL
_openssl_get_handle ( string $cipher, string $mode ) : string Get OpenSSL handle
_openssl_initialize ( array $params ) : void Initialize OpenSSL
strlen ( string $str ) : integer Byte-safe strlen()
substr ( string $str, integer $start, integer $length = NULL ) : string Byte-safe substr()

Method Details

__construct() public method

Class constructor
public __construct ( array $params = [] ) : void
$params array Configuration parameters
return void

__get() public method

__get() magic
public __get ( string $key ) : mixed
$key string Property name
return mixed

_cipher_alias() protected method

Tries to translate cipher names between MCrypt and OpenSSL's "dialects".
protected _cipher_alias ( string &$cipher ) : void
$cipher string Cipher name
return void

_get_params() protected method

Get params
protected _get_params ( array $params ) : array
$params array Input parameters
return array

_mcrypt_decrypt() protected method

Decrypt via MCrypt
protected _mcrypt_decrypt ( string $data, array $params ) : string
$data string Encrypted data
$params array Input parameters
return string

_mcrypt_encrypt() protected method

Encrypt via MCrypt
protected _mcrypt_encrypt ( string $data, array $params ) : string
$data string Input data
$params array Input parameters
return string

_mcrypt_get_handle() protected method

Get MCrypt handle
protected _mcrypt_get_handle ( string $cipher, string $mode ) : resource
$cipher string Cipher name
$mode string Encryption mode
return resource

_mcrypt_initialize() protected method

Initialize MCrypt
protected _mcrypt_initialize ( array $params ) : void
$params array Configuration parameters
return void

_openssl_decrypt() protected method

Decrypt via OpenSSL
protected _openssl_decrypt ( string $data, array $params ) : string
$data string Encrypted data
$params array Input parameters
return string

_openssl_encrypt() protected method

Encrypt via OpenSSL
protected _openssl_encrypt ( string $data, array $params ) : string
$data string Input data
$params array Input parameters
return string

_openssl_get_handle() protected method

Get OpenSSL handle
protected _openssl_get_handle ( string $cipher, string $mode ) : string
$cipher string Cipher name
$mode string Encryption mode
return string

_openssl_initialize() protected method

Initialize OpenSSL
protected _openssl_initialize ( array $params ) : void
$params array Configuration parameters
return void

create_key() public method

Create a random key
public create_key ( integer $length ) : string
$length integer Output length
return string

decrypt() public method

Decrypt
public decrypt ( string $data, array $params = NULL ) : string
$data string Encrypted data
$params array Input parameters
return string

encrypt() public method

Encrypt
public encrypt ( string $data, array $params = NULL ) : string
$data string Input data
$params array Input parameters
return string

hkdf() public method

HKDF
public hkdf ( $key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '' ) : string
$key Input key
$digest A SHA-2 hashing algorithm
$salt Optional salt
$length Output length (defaults to the selected digest size)
$info Optional context/application-specific info
return string A pseudo-random key

initialize() public method

Initialize
public initialize ( array $params ) : CI_Encryption
$params array Configuration parameters
return CI_Encryption

strlen() protected static method

Byte-safe strlen()
protected static strlen ( string $str ) : integer
$str string
return integer

substr() protected static method

Byte-safe substr()
protected static substr ( string $str, integer $start, integer $length = NULL ) : string
$str string
$start integer
$length integer
return string

Property Details

$_cipher protected_oe property

Encryption cipher
protected string $_cipher
return string

$_digests protected_oe property

name => digest size pairs
protected array $_digests
return array

$_driver protected_oe property

PHP extension to be used
protected string $_driver
return string

$_drivers protected_oe property

List of usable drivers (PHP extensions)
protected array $_drivers
return array

$_handle protected_oe property

Cipher handle
protected mixed $_handle
return mixed

$_key protected_oe property

Encryption key
protected string $_key
return string

$_mode protected_oe property

Cipher mode
protected string $_mode
return string

$_modes protected_oe property

List of available modes
protected array $_modes
return array

$func_override protected_oe static_oe property

mbstring.func_override flag
protected static bool $func_override
return boolean