PHP Class CI_Encrypt, TastyIgniter

Provides two-way keyed encoding using XOR Hashing and Mcrypt
Author: ExpressionEngine Dev Team
Afficher le fichier Open project: tastyigniter/tastyigniter Class Usage Examples

Méthodes publiques

Свойство Type Description
$encryption_key string Reference to the user's encryption key

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

Initialize Encryption class
public __construct ( ) : void
Résultat void

_add_cipher_noise() protected méthode

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
Résultat string

_get_cipher() protected méthode

Get Mcrypt cipher Value
protected _get_cipher ( ) : integer
Résultat integer

_get_mode() protected méthode

Get Mcrypt Mode Value
protected _get_mode ( ) : integer
Résultat integer

_remove_cipher_noise() protected méthode

Function description
protected _remove_cipher_noise ( string $data, string $key ) : string
$data string
$key string
Résultat string

_xor_decode() protected méthode

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

_xor_merge() protected méthode

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

decode() public méthode

Reverses the above process
public decode ( $string, $key = '' ) : string
Résultat string

encode() public méthode

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
Résultat string

encode_from_legacy() public méthode

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
Résultat string

get_key() public méthode

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
Résultat string

hash() public méthode

Hash encode a string
public hash ( $str ) : string
Résultat string

mcrypt_decode() public méthode

Decrypt using Mcrypt
public mcrypt_decode ( $data, $key ) : string
Résultat string

mcrypt_encode() public méthode

Encrypt using Mcrypt
public mcrypt_encode ( $data, $key ) : string
Résultat string

set_cipher() public méthode

Set the Mcrypt Cipher
public set_cipher ( $cipher ) : CI_Encrypt
Résultat CI_Encrypt

set_hash() public méthode

Set the Hash type
public set_hash ( $type = 'sha1' ) : void
Résultat void

set_key() public méthode

Set the encryption key
public set_key ( $key = '' ) : CI_Encrypt
Résultat CI_Encrypt

set_mode() public méthode

Set the Mcrypt Mode
public set_mode ( $mode ) : CI_Encrypt
Résultat CI_Encrypt

Property Details

$_hash_type protected_oe property

Type of hash operation
protected string $_hash_type
Résultat string

$_mcrypt_cipher protected_oe property

Current cipher to be used with mcrypt
protected string $_mcrypt_cipher
Résultat string

$_mcrypt_exists protected_oe property

Flag for the existence of mcrypt
protected bool $_mcrypt_exists
Résultat boolean

$_mcrypt_mode protected_oe property

Method for encrypting/decrypting data
protected int $_mcrypt_mode
Résultat integer

$encryption_key public_oe property

Reference to the user's encryption key
public string $encryption_key
Résultat string