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 |
can be used when mcrypt is available
Definition at line 30 of file mcpt.php.
zCryptDrv_mcrypt::__construct | ( | ) |
Reimplemented from zCore.
Definition at line 39 of file mcpt.php.
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 }
zCryptDrv_mcrypt::zCryptDrv_mcrypt | ( | ) |
Definition at line 36 of file mcpt.php.
References __construct().
00036 { 00037 $this->__construct(); 00038 }
zCryptDrv_mcrypt::mct | ( | ) |
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.
returns base64 Encoded encrypted string
$str | string string to encode. | |
$key | string optionally you can specify a key/password with which to encrypt. |
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.
$str | string string to decode. | |
$key | string optionally you can specify a key/password with which to decrypt. |
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.
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
$str | string string to encode. | |
$key | string optionally you can specify a key/password with which to encrypt. |
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()
$str | string string to decode. | |
$key | string optionally you can specify a key/password with which to decrypt. |
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.
$str | string string that to encode | |
$key | string optionally key/password with which to encode |
Definition at line 161 of file mcpt.php.
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 }
zCryptDrv_mcrypt::tdcd | ( | $ | str, | |
$ | key = NULL | |||
) |
decrypts a string thats encoded using tenc() method.
$str | string string that to decode | |
$key | string optionally key/password with which to decode |
Definition at line 179 of file mcpt.php.
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 }
zCryptDrv_mcrypt::encrypt | ( | $ | str, | |
$ | key = NULL | |||
) |
zCryptDrv_mcrypt::decrypt | ( | $ | str, | |
$ | key = NULL | |||
) |
zCryptDrv_mcrypt::$key |