\CI_Encrypt

CodeIgniter Encryption Class

Provides two-way keyed encoding using XOR Hashing and Mcrypt

Summary

Methods
Properties
Constants
__construct()
get_key()
set_key()
encode()
decode()
encode_from_legacy()
_xor_encode()
_xor_decode()
_xor_merge()
mcrypt_encode()
mcrypt_decode()
_add_cipher_noise()
_remove_cipher_noise()
set_cipher()
set_mode()
_get_cipher()
_get_mode()
set_hash()
hash()
sha1()
$CI
$encryption_key
$_hash_type
$_mcrypt_exists
$_mcrypt_cipher
$_mcrypt_mode
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$CI

$CI : 

Type

$encryption_key

$encryption_key : 

Type

$_hash_type

$_hash_type : 

Type

$_mcrypt_exists

$_mcrypt_exists : 

Type

$_mcrypt_cipher

$_mcrypt_cipher : 

Type

$_mcrypt_mode

$_mcrypt_mode : 

Type

Methods

__construct()

__construct() 

Constructor

Simply determines whether the mcrypt library exists.

get_key()

get_key(  $key = '') : string

Fetch the encryption key

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

Parameters

$key

Returns

string

set_key()

set_key(  $key = '') : void

Set the encryption key

Parameters

$key

encode()

encode(  $string,   $key = '') : string

Encode

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 (if supported) 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.

Parameters

$string
$key

Returns

string

decode()

decode(  $string,   $key = '') : string

Decode

Reverses the above process

Parameters

$string
$key

Returns

string

encode_from_legacy()

encode_from_legacy(  $string,   $legacy_mode = MCRYPT_MODE_ECB,   $key = '') : string

Encode from Legacy

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 http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption

Parameters

$string
$legacy_mode
$key

Returns

string

_xor_encode()

_xor_encode(  $string,   $key) : string

XOR Encode

Takes a plain-text string and key as input and generates an encoded bit-string using XOR

Parameters

$string
$key

Returns

string

_xor_decode()

_xor_decode(  $string,   $key) : string

XOR Decode

Takes an encoded string and key as input and generates the plain-text original message

Parameters

$string
$key

Returns

string

_xor_merge()

_xor_merge(  $string,   $key) : string

XOR key + string Combiner

Takes a string and key as input and computes the difference using XOR

Parameters

$string
$key

Returns

string

mcrypt_encode()

mcrypt_encode(  $data,   $key) : string

Encrypt using Mcrypt

Parameters

$data
$key

Returns

string

mcrypt_decode()

mcrypt_decode(  $data,   $key) : string

Decrypt using Mcrypt

Parameters

$data
$key

Returns

string

_add_cipher_noise()

_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

Function description

Parameters

$data
$key

Returns

string

_remove_cipher_noise()

_remove_cipher_noise(  $data,   $key) : \type

Removes permuted noise from the IV + encrypted data, reversing _add_cipher_noise()

Function description

Parameters

$data
$key

Returns

\type

set_cipher()

set_cipher(  $cipher) : string

Set the Mcrypt Cipher

Parameters

$cipher

Returns

string

set_mode()

set_mode(  $mode) : string

Set the Mcrypt Mode

Parameters

$mode

Returns

string

_get_cipher()

_get_cipher() : string

Get Mcrypt cipher Value

Returns

string

_get_mode()

_get_mode() : string

Get Mcrypt Mode Value

Returns

string

set_hash()

set_hash(  $type = 'sha1') : string

Set the Hash type

Parameters

$type

Returns

string

hash()

hash(  $str) : string

Hash encode a string

Parameters

$str

Returns

string

sha1()

sha1(  $str) : string

Generate an SHA1 Hash

Parameters

$str

Returns

string