Public Member Functions | |
__construct (array $data=array()) | |
init ($key) | |
encrypt ($data) | |
decrypt ($data) | |
__destruct () | |
Protected Member Functions | |
_reset () |
Definition at line 35 of file Mcrypt.php.
Constuctor
array | $data |
Definition at line 42 of file Mcrypt.php.
00043 { 00044 parent::__construct($data); 00045 }
__destruct | ( | ) |
Desctruct cipher module
Definition at line 116 of file Mcrypt.php.
00117 { 00118 if ($this->getHandler()) { 00119 $this->_reset(); 00120 } 00121 }
_reset | ( | ) | [protected] |
Definition at line 123 of file Mcrypt.php.
00124 { 00125 mcrypt_generic_deinit($this->getHandler()); 00126 mcrypt_module_close($this->getHandler()); 00127 }
decrypt | ( | $ | data | ) |
Decrypt data
string | $data encrypted string |
Definition at line 101 of file Mcrypt.php.
00102 { 00103 if (!$this->getHandler()) { 00104 throw new Varien_Exception('Crypt module is not initialized.'); 00105 } 00106 if (strlen($data) == 0) { 00107 return $data; 00108 } 00109 return mdecrypt_generic($this->getHandler(), $data); 00110 }
encrypt | ( | $ | data | ) |
Encrypt data
string | $data source string |
Definition at line 84 of file Mcrypt.php.
00085 { 00086 if (!$this->getHandler()) { 00087 throw new Varien_Exception('Crypt module is not initialized.'); 00088 } 00089 if (strlen($data) == 0) { 00090 return $data; 00091 } 00092 return mcrypt_generic($this->getHandler(), $data); 00093 }
init | ( | $ | key | ) |
Initialize mcrypt module
string | $key cipher private key |
Definition at line 53 of file Mcrypt.php.
00054 { 00055 if (!$this->getCipher()) { 00056 $this->setCipher(MCRYPT_BLOWFISH); 00057 } 00058 00059 if (!$this->getMode()) { 00060 $this->setMode(MCRYPT_MODE_ECB); 00061 } 00062 00063 $this->setHandler(mcrypt_module_open($this->getCipher(), '', $this->getMode(), '')); 00064 $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($this->getHandler()), MCRYPT_RAND); 00065 00066 $maxKeySize = mcrypt_enc_get_key_size($this->getHandler()); 00067 00068 if (iconv_strlen($key, 'UTF-8')>$maxKeySize) { 00069 $this->setHandler(null); 00070 throw new Varien_Exception('Maximum key size must should be smaller '.$maxKeySize); 00071 } 00072 00073 mcrypt_generic_init($this->getHandler(), $key, $iv); 00074 00075 return $this; 00076 }