Loading Please wait...

zCryptDrv_mcrypt Class Reference
[Zigmoyd Encryption System.]

MCrypt adapter for Zigmoyd Encryption System. More...

Inheritance diagram for zCryptDrv_mcrypt:

Inheritance graph
[legend]
Collaboration diagram for zCryptDrv_mcrypt:

Collaboration graph
[legend]

Public Member Functions

 zCryptDrv_mcrypt ()
 __construct ()
 mct ()
 Generates Numbers dependng on Time.
 encode ($str, $key=NULL)
 encodes a string using static IV.
 decode ($str, $key=NULL)
 Decrypts a string which is encrypted using encode() method using static IV.
 denc ($str, $key=NULL)
 encodes a string using Dynamic IV.
 ddcd ($str, $key=NULL)
 decodes a string using dynamic IV.
 tenc ($str, $key=NULL)
 Time based encryption.
 tdcd ($str, $key=NULL)
 decrypts a string thats encoded using tenc() method.
 encrypt ($str, $key=NULL)
 Alias of encode().
 decrypt ($str, $key=NULL)
 Alias of decode().

Data Fields

 $iv
 $key
 $iv_size
 $div

Detailed Description

MCrypt adapter for Zigmoyd Encryption System.

can be used when mcrypt is available

Definition at line 30 of file mcpt.php.


Constructor & Destructor Documentation

zCryptDrv_mcrypt::__construct (  ) 

Reimplemented from zCore.

Definition at line 39 of file mcpt.php.

References $key, and $val.

Referenced by zCryptDrv_mcrypt().

00039                         {
00040     parent::__construct();
00041     if(!defined('ENC_BIN')){define('ENC_BIN', null);}
00042     if(!defined('ENC_DEC')){define('ENC_DEC', null);}
00043     $tmp_deff = parse_ini_file(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.'mcpt.ini.php', false);
00044     foreach($tmp_deff as $key => $val){
00045       if($key != 'iv' && $key != 'key'){
00046         if(!defined($key)){define($key, $val);}
00047       }
00048     }
00049     $this->iv = base64_decode($tmp_deff['iv']);
00050     $this->key = md5($tmp_deff['mkey']);
00051     //Block for Dynamic encryption
00052     $this->iv_size = mcrypt_get_iv_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00053     $this->div = mcrypt_create_iv($this->iv_size, SEC_MCRYPT_IV_SRC);
00054   }


Member Function Documentation

zCryptDrv_mcrypt::zCryptDrv_mcrypt (  ) 

Definition at line 36 of file mcpt.php.

References __construct().

00036                              {
00037     $this->__construct();
00038   }

Here is the call graph for this function:

zCryptDrv_mcrypt::mct (  ) 

Generates Numbers dependng on Time.

Returns:
float

Definition at line 60 of file mcpt.php.

Referenced by tdcd(), and tenc().

00060                 {
00061     list($usec, $sec) = explode(" ", microtime());
00062     return ((float)$usec + (float)$sec);
00063   }

zCryptDrv_mcrypt::encode ( str,
key = NULL 
)

encodes a string using static IV.

Encrypts a string using mcrypt encryption settings on the configuration files. By default uses the encryption key set on the Configuration files. However you can supply another one through the second optional argument.

Warning:
encrypts using Static IV set on Configuration Files.

returns base64 Encoded encrypted string

Parameters:
$str string string to encode.
$key string optionally you can specify a key/password with which to encrypt.
Returns:
string

Definition at line 76 of file mcpt.php.

References $key.

Referenced by encrypt().

00076                                     {
00077     if(is_null($key)){$key = $this->key;}
00078     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00079     if(strlen($key) > $key_size){
00080       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00081       $key = substr($key, 0, $key_size);
00082     }
00083     return mcrypt_encrypt(SEC_MCRYPT_ALGO, $key, base64_encode($str), SEC_MCRYPT_MODE, $this->iv);
00084   }

zCryptDrv_mcrypt::decode ( str,
key = NULL 
)

Decrypts a string which is encrypted using encode() method using static IV.

By default uses the encryption key set on the Configuration files. However you can supply another one through the second optional argument.

Warning:
encrypts using Static IV set on Configuration Files.
Parameters:
$str string string to decode.
$key string optionally you can specify a key/password with which to decrypt.
Returns:
string

Definition at line 95 of file mcpt.php.

References $key.

Referenced by decrypt().

00095                                     {
00096     if(is_null($key)){$key = $this->key;}
00097     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00098     if(strlen($key) > $key_size){
00099       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00100       $key = substr($key, 0, $key_size);
00101     }
00102     //return trim(base64_decode(@mcrypt_decrypt(SEC_MCRYPT_ALGO, $key, $str, SEC_MCRYPT_MODE, $this->iv)));
00103     return base64_decode(trim(@mcrypt_decrypt(SEC_MCRYPT_ALGO, $key, $str, SEC_MCRYPT_MODE, $this->iv)));
00104   }

zCryptDrv_mcrypt::denc ( str,
key = NULL 
)

encodes a string using Dynamic IV.

Encrypts a string using mcrypt encryption settings on the configuration files. By default uses the encryption key set on the Configuration files. However you can supply another one through the second optional argument.

Warning:
remember It uses a dynamically generated IV so it doesn't uses the IV set on configuration file(s)

The Dynamic IV used for this encryption is created only once in an Internal Instance. so if you call denc() multiple times it will use NOT different IVs. but when denc() is called on another request it will use a different IV. e.g. When Zigmoyd gets a HTTP requests it generates a dynamic IV which will be used for that Session only. whenever that session is gone and a new Request arrives another Dynamic IV is generated for that session. so all calls to denc() in same session will use the same dynami IV.

returns base64 Encoded encrypted string

Parameters:
$str string string to encode.
$key string optionally you can specify a key/password with which to encrypt.
Returns:
string

Definition at line 121 of file mcpt.php.

References $key.

00121                                   {
00122     if(is_null($key)){$key = $this->key;}
00123     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00124     if(strlen($key) > $key_size){
00125       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00126       $key = substr($key, 0, $key_size);
00127     }
00128     return mcrypt_encrypt(SEC_MCRYPT_ALGO, $key, base64_encode($str), SEC_MCRYPT_MODE, $this->div);
00129   }

zCryptDrv_mcrypt::ddcd ( str,
key = NULL 
)

decodes a string using dynamic IV.

decodes a string which has been encoded using denc()

See also:
denc()
Parameters:
$str string string to decode.
$key string optionally you can specify a key/password with which to decrypt.
Returns:
string

Definition at line 139 of file mcpt.php.

References $key.

00139                                   {
00140     if(is_null($key)){$key = $this->key;}
00141     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00142     if(strlen($key) > $key_size){
00143       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00144       $key = substr($key, 0, $key_size);
00145     }
00146     return trim(base64_decode(mcrypt_decrypt(SEC_MCRYPT_ALGO, $key, $str, SEC_MCRYPT_MODE, $this->div)));
00147   }

zCryptDrv_mcrypt::tenc ( str,
key = NULL 
)

Time based encryption.

Concates the encryption key/password with Current Time String. the Time String can be in second or Microsecond based on your Configuration settings. if its set to microsecond the encrypted string is valid for 1 microsecond only. and if its set it second the encrypted string is valid for 1 second only. by defalut takes encryption key/password from the configuration file. However you can optionally supply key with which to encrypt.

Parameters:
$str string string that to encode
$key string optionally key/password with which to encode
Returns:
string

Definition at line 161 of file mcpt.php.

References $key, and mct().

00161                                   {
00162     if(is_null($key)){$key = $this->key;}
00163     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00164     if(strlen($key) > $key_size){
00165       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00166       $key = substr($key, 0, $key_size);
00167     }
00168     if(SEC_MCRYPT_TIMEOUT == 'm'){$t = time();}elseif(SEC_MCRYPT_TIMEOUT == 's'){$t = $this->mct();}
00169     return mcrypt_encrypt(SEC_MCRYPT_ALGO, $key.$t, base64_encode($str), SEC_MCRYPT_MODE, $this->div);
00170   }

Here is the call graph for this function:

zCryptDrv_mcrypt::tdcd ( str,
key = NULL 
)

decrypts a string thats encoded using tenc() method.

See also:
tenc()
Parameters:
$str string string that to decode
$key string optionally key/password with which to decode
Returns:
string

Definition at line 179 of file mcpt.php.

References $key, and mct().

00179                                   {
00180     if(is_null($key)){$key = $this->key;}
00181     $key_size = mcrypt_get_key_size(SEC_MCRYPT_ALGO, SEC_MCRYPT_MODE);
00182     if(strlen($key) > $key_size){
00183       //perror("Length of the Key is too large for this algorighm<br />Supported Key size $key_size. Size of your key is ".strlen($key).". <br /> Either Select a Different Algorithm or select a Different key");
00184       $key = substr($key, 0, $key_size);
00185     }
00186     if(SEC_MCRYPT_TIMEOUT == 'm'){$t = time();}elseif(SEC_MCRYPT_TIMEOUT == 's'){$t = $this->mct();}
00187     //return trim(base64_decode(mcrypt_decrypt(SEC_MCRYPT_ALGO, $key.$t, $str, SEC_MCRYPT_MODE, $this->div)));
00188     return base64_decode(trim(mcrypt_decrypt(SEC_MCRYPT_ALGO, $key.$t, $str, SEC_MCRYPT_MODE, $this->div)));
00189   }

Here is the call graph for this function:

zCryptDrv_mcrypt::encrypt ( str,
key = NULL 
)

Alias of encode().

See also:
encode()
Parameters:
$str string String that yo want to encode.
$key string key with which you want to decode.
Returns:
string

Definition at line 198 of file mcpt.php.

References $key, and encode().

00198                                      {
00199     return $this->encode($str, $key);
00200   }

Here is the call graph for this function:

zCryptDrv_mcrypt::decrypt ( str,
key = NULL 
)

Alias of decode().

See also:
decode()
Parameters:
$str string Sencrypted string that you want to decode.
$key string key with which you want to decode.
Returns:
string

Definition at line 209 of file mcpt.php.

References $key, and decode().

00209                                      {
00210     return $this->decode($str, $key);
00211   }

Here is the call graph for this function:


Field Documentation

zCryptDrv_mcrypt::$iv

Definition at line 31 of file mcpt.php.

zCryptDrv_mcrypt::$key

Definition at line 32 of file mcpt.php.

Referenced by __construct(), ddcd(), decode(), decrypt(), denc(), encode(), encrypt(), tdcd(), and tenc().

zCryptDrv_mcrypt::$iv_size

Definition at line 33 of file mcpt.php.

zCryptDrv_mcrypt::$div

Definition at line 34 of file mcpt.php.


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

Generated on Mon Oct 27 23:53:43 2008 for zigmoyd.kdevelop by doxygen 1.5.6