PHP Class CI_Encrypt, TastyIgniter

Provides two-way keyed encoding using XOR Hashing and Mcrypt
Author: ExpressionEngine Dev Team
显示文件 Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$encryption_key string Reference to the user's encryption key

Protected Properties

Property Type Description
$_hash_type string Type of hash operation
$_mcrypt_cipher string Current cipher to be used with mcrypt
$_mcrypt_exists boolean Flag for the existence of mcrypt
$_mcrypt_mode integer Method for encrypting/decrypting data

Public Methods

Method Description
__construct ( ) : void Initialize Encryption class
decode ( $string, $key = '' ) : string Decode
encode ( $string, $key = '' ) : string Encode
encode_from_legacy ( $string, $legacy_mode = MCRYPT_MODE_ECB, $key = '' ) : string Encode from Legacy
get_key ( $key = '' ) : string Fetch the encryption key
hash ( $str ) : string Hash encode a string
mcrypt_decode ( $data, $key ) : string Decrypt using Mcrypt
mcrypt_encode ( $data, $key ) : string Encrypt using Mcrypt
set_cipher ( $cipher ) : CI_Encrypt Set the Mcrypt Cipher
set_hash ( $type = 'sha1' ) : void Set the Hash type
set_key ( $key = '' ) : CI_Encrypt Set the encryption key
set_mode ( $mode ) : CI_Encrypt Set the Mcrypt Mode

Protected Methods

Method Description
_add_cipher_noise ( $data, $key ) : string Adds permuted noise to the IV + encrypted data to protect against Man-in-the-middle attacks on CBC mode ciphers http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
_get_cipher ( ) : integer Get Mcrypt cipher Value
_get_mode ( ) : integer Get Mcrypt Mode Value
_remove_cipher_noise ( string $data, string $key ) : string Removes permuted noise from the IV + encrypted data, reversing _add_cipher_noise()
_xor_decode ( $string, $key ) : string XOR Decode
_xor_merge ( $string, $key ) : string XOR key + string Combiner

Method Details

__construct() public method

Initialize Encryption class
public __construct ( ) : void
return void

_add_cipher_noise() protected method

Adds permuted noise to the IV + encrypted data to protect against Man-in-the-middle attacks on CBC mode ciphers http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
protected _add_cipher_noise ( $data, $key ) : string
return string

_get_cipher() protected method

Get Mcrypt cipher Value
protected _get_cipher ( ) : integer
return integer

_get_mode() protected method

Get Mcrypt Mode Value
protected _get_mode ( ) : integer
return integer

_remove_cipher_noise() protected method

Function description
protected _remove_cipher_noise ( string $data, string $key ) : string
$data string
$key string
return string

_xor_decode() protected method

Takes an encoded string and key as input and generates the plain-text original message
protected _xor_decode ( $string, $key ) : string
return string

_xor_merge() protected method

Takes a string and key as input and computes the difference using XOR
protected _xor_merge ( $string, $key ) : string
return string

decode() public method

Reverses the above process
public decode ( $string, $key = '' ) : string
return string

encode() public method

Encodes the message string using bitwise XOR encoding. The key is combined with a random hash, and then it too gets converted using XOR. The whole thing is then run through mcrypt using the randomized key. The end result is a double-encrypted message string that is randomized with each call to this function, even if the supplied message and key are the same.
public encode ( $string, $key = '' ) : string
return string

encode_from_legacy() public method

Takes an encoded string from the original Encryption class algorithms and returns a newly encoded string using the improved method added in 2.0.0 This allows for backwards compatibility and a method to transition to the new encryption algorithms. For more details, see https://codeigniter.com/user_guide/installation/upgrade_200.html#encryption
public encode_from_legacy ( $string, $legacy_mode = MCRYPT_MODE_ECB, $key = '' ) : string
return string

get_key() public method

Returns it as MD5 in order to have an exact-length 128 bit key. Mcrypt is sensitive to keys that are not the correct length
public get_key ( $key = '' ) : string
return string

hash() public method

Hash encode a string
public hash ( $str ) : string
return string

mcrypt_decode() public method

Decrypt using Mcrypt
public mcrypt_decode ( $data, $key ) : string
return string

mcrypt_encode() public method

Encrypt using Mcrypt
public mcrypt_encode ( $data, $key ) : string
return string

set_cipher() public method

Set the Mcrypt Cipher
public set_cipher ( $cipher ) : CI_Encrypt
return CI_Encrypt

set_hash() public method

Set the Hash type
public set_hash ( $type = 'sha1' ) : void
return void

set_key() public method

Set the encryption key
public set_key ( $key = '' ) : CI_Encrypt
return CI_Encrypt

set_mode() public method

Set the Mcrypt Mode
public set_mode ( $mode ) : CI_Encrypt
return CI_Encrypt

Property Details

$_hash_type protected_oe property

Type of hash operation
protected string $_hash_type
return string

$_mcrypt_cipher protected_oe property

Current cipher to be used with mcrypt
protected string $_mcrypt_cipher
return string

$_mcrypt_exists protected_oe property

Flag for the existence of mcrypt
protected bool $_mcrypt_exists
return boolean

$_mcrypt_mode protected_oe property

Method for encrypting/decrypting data
protected int $_mcrypt_mode
return integer

$encryption_key public_oe property

Reference to the user's encryption key
public string $encryption_key
return string