My Project
 All Data Structures Namespaces Functions Variables
Public Member Functions | Data Fields
CI_Encrypt Class Reference

Public Member Functions

 __construct ()
 
 get_key ($key= '')
 
 set_key ($key= '')
 
 encode ($string, $key= '')
 
 decode ($string, $key= '')
 
 encode_from_legacy ($string, $legacy_mode=MCRYPT_MODE_ECB, $key= '')
 
 _xor_encode ($string, $key)
 
 _xor_decode ($string, $key)
 
 _xor_merge ($string, $key)
 
 mcrypt_encode ($data, $key)
 
 mcrypt_decode ($data, $key)
 
 _add_cipher_noise ($data, $key)
 
 _remove_cipher_noise ($data, $key)
 
 set_cipher ($cipher)
 
 set_mode ($mode)
 
 _get_cipher ()
 
 _get_mode ()
 
 set_hash ($type= 'sha1')
 
 hash ($str)
 
 sha1 ($str)
 

Data Fields

 $CI
 
 $encryption_key = ''
 
 $_hash_type = 'sha1'
 
 $_mcrypt_exists = FALSE
 
 $_mcrypt_cipher
 
 $_mcrypt_mode
 

Constructor & Destructor Documentation

__construct ( )

Constructor

Simply determines whether the mcrypt library exists.

Member Function Documentation

_add_cipher_noise (   $data,
  $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

private

Parameters
string
string
Returns
string
_get_cipher ( )

Get Mcrypt cipher Value

private

Returns
string
_get_mode ( )

Get Mcrypt Mode Value

private

Returns
string
_remove_cipher_noise (   $data,
  $key 
)

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

Function description

public

Parameters
type
Returns
type
_xor_decode (   $string,
  $key 
)

XOR Decode

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

private

Parameters
string
string
Returns
string
_xor_encode (   $string,
  $key 
)

XOR Encode

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

private

Parameters
string
string
Returns
string
_xor_merge (   $string,
  $key 
)

XOR key + string Combiner

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

private

Parameters
string
string
Returns
string
decode (   $string,
  $key = '' 
)

Decode

Reverses the above process

public

Parameters
string
string
Returns
string
encode (   $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.

public

Parameters
stringthe string to encode
stringthe key
Returns
string
encode_from_legacy (   $string,
  $legacy_mode = MCRYPT_MODE_ECB,
  $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

public

Parameters
string
int(mcrypt mode constant)
string
Returns
string
get_key (   $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

public

Parameters
string
Returns
string
hash (   $str)

Hash encode a string

public

Parameters
string
Returns
string
mcrypt_decode (   $data,
  $key 
)

Decrypt using Mcrypt

public

Parameters
string
string
Returns
string
mcrypt_encode (   $data,
  $key 
)

Encrypt using Mcrypt

public

Parameters
string
string
Returns
string
set_cipher (   $cipher)

Set the Mcrypt Cipher

public

Parameters
constant
Returns
string
set_hash (   $type = 'sha1')

Set the Hash type

public

Parameters
string
Returns
string
set_key (   $key = '')

Set the encryption key

public

Parameters
string
Returns
void
set_mode (   $mode)

Set the Mcrypt Mode

public

Parameters
constant
Returns
string
sha1 (   $str)

Generate an SHA1 Hash

public

Parameters
string
Returns
string

The documentation for this class was generated from the following file: