Class CI_Encrypt - echiong/testRepo GitHub Wiki
##Class CI_Encrypt
CodeIgniter Encryption Class
Provides two-way keyed encoding using XOR Hashing and Mcrypt
Package: [[CodeIgniter<a href="Package CodeIgniter.Libraries.md">Libraries]]
Category:
Libraries
Author:
ExpressionEngine Dev Team
Link:
http://codeigniter.com/user_guide/libraries/encryption.html
Located at system/libraries/Encrypt.php
##Methods summary
public __construct ( )
Constructor
Simply determines whether the mcrypt library exists.
public string get_key ( string $key = '' )
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
string
Returns
string
public set_key ( string $key = '' )
Set the encryption key
Parameters
$key
string
public string encode ( string $string, string $key = '' )
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
string
the string to encode
$key
string
the key
Returns
string
public string decode ( string $string, string $key = '' )
Decode
Reverses the above process
Parameters
$string
string
$key
string
Returns
string
public string encode_from_legacy ( string $string, integer $legacy_mode = MCRYPT_MODE_ECB, string $key = '' )
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
string
$legacy_mode
integer
(mcrypt mode constant)
$key
string
Returns
string
public string _xor_encode ( string $string, string $key )
XOR Encode
Takes a plain-text string and key as input and generates an encoded bit-string using XOR
Parameters
$string
string
$key
string
Returns
string
public string _xor_decode ( string $string, string $key )
XOR Decode
Takes an encoded string and key as input and generates the plain-text original message
Parameters
$string
string
$key
string
Returns
string
public string _xor_merge ( string $string, string $key )
XOR key + string Combiner
Takes a string and key as input and computes the difference using XOR
Parameters
$string
string
$key
string
Returns
string
public string mcrypt_encode ( string $data, string $key )
Encrypt using Mcrypt
Parameters
$data
string
$key
string
Returns
string
public string mcrypt_decode ( string $data, string $key )
Decrypt using Mcrypt
Parameters
$data
string
$key
string
Returns
string
public string _add_cipher_noise ( string $data, string $key )
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
string
$key
string
Returns
string
public type _remove_cipher_noise ( type $data, mixed $key )
Removes permuted noise from the IV + encrypted data, reversing _add_cipher_noise()
Function description
Parameters
$data
type
$key
Returns
type
public string set_cipher ( constant $cipher )
Set the Mcrypt Cipher
Parameters
$cipher
constant
Returns
string
public string set_mode ( constant $mode )
Set the Mcrypt Mode
Parameters
$mode
constant
Returns
string
public string _get_cipher ( )
Get Mcrypt cipher Value
Returns
string
public string _get_mode ( )
Get Mcrypt Mode Value
Returns
string
public string set_hash ( string $type = 'sha1' )
Set the Hash type
Parameters
$type
string
Returns
string
public string hash ( string $str )
Hash encode a string
Parameters
$str
string
Returns
string
public string sha1 ( string $str )
Generate an SHA1 Hash
Parameters
$str
string
Returns
string
<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="CI" id="$CI">
<td class="attributes"><code>
public
mixed
</code></td>
<td class="name">
$CI
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="encryption_key" id="$encryption_key">
<td class="attributes"><code>
public
string
</code></td>
<td class="name">
$encryption_key
''
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="_hash_type" id="$_hash_type">
<td class="attributes"><code>
public
string
</code></td>
<td class="name">
$_hash_type
'sha1'
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="_mcrypt_exists" id="$_mcrypt_exists">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$_mcrypt_exists
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="_mcrypt_cipher" id="$_mcrypt_cipher">
<td class="attributes"><code>
public
mixed
</code></td>
<td class="name">
$_mcrypt_cipher
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="_mcrypt_mode" id="$_mcrypt_mode">
<td class="attributes"><code>
public
mixed
</code></td>
<td class="name">
$_mcrypt_mode
<div class="description detailed">
</div>
</div></td>
</tr>
</table>