Public Member Functions | |
setHelper ($helper) | |
getHash ($password, $salt=false) | |
hash ($data) | |
validateHash ($password, $hash) | |
encrypt ($data) | |
decrypt ($data) | |
validateKey ($key) | |
Protected Member Functions | |
_getCrypt ($key=null) | |
Protected Attributes | |
$_crypt | |
$_helper |
Definition at line 34 of file Encryption.php.
_getCrypt | ( | $ | key = null |
) | [protected] |
Instantiate crypt model
string | $key |
Definition at line 114 of file Encryption.php.
00115 { 00116 if (!$this->_crypt) { 00117 if (null === $key) { 00118 $key = (string)Mage::getConfig()->getNode('global/crypt/key'); 00119 } 00120 $this->_crypt = Varien_Crypt::factory()->init($key); 00121 } 00122 return $this->_crypt; 00123 }
decrypt | ( | $ | data | ) |
Decrypt a string
string | $data |
Definition at line 142 of file Encryption.php.
00143 { 00144 return str_replace("\x0", '', trim($this->_getCrypt()->decrypt(base64_decode((string)$data)))); 00145 }
encrypt | ( | $ | data | ) |
Encrypt a string
string | $data |
Definition at line 131 of file Encryption.php.
getHash | ( | $ | password, | |
$ | salt = false | |||
) |
Generate a [salted] hash.
$salt can be: false - a random will be generated integer - a random with specified length will be generated string
string | $password | |
mixed | $salt |
Definition at line 69 of file Encryption.php.
00070 { 00071 if (is_integer($salt)) { 00072 $salt = $this->_helper->getRandomString($salt); 00073 } 00074 return $salt === false ? $this->hash($password) : $this->hash($salt . $password) . ':' . $salt; 00075 }
hash | ( | $ | data | ) |
Hash a string
string | $data |
Definition at line 83 of file Encryption.php.
00084 { 00085 return md5($data); 00086 }
setHelper | ( | $ | helper | ) |
Set helper instance
Mage_Core_Helper_Data | $helper |
Definition at line 51 of file Encryption.php.
validateHash | ( | $ | password, | |
$ | hash | |||
) |
Validate hash against hashing method (with or without salt)
string | $password | |
string | $hash |
Exception |
Definition at line 96 of file Encryption.php.
00097 { 00098 $hashArr = explode(':', $hash); 00099 switch (count($hashArr)) { 00100 case 1: 00101 return $this->hash($password) === $hash; 00102 case 2: 00103 return $this->hash($hashArr[1] . $password) === $hashArr[0]; 00104 } 00105 Mage::throwException('Invalid hash.'); 00106 }
validateKey | ( | $ | key | ) |
Return crypt model, instantiate if it is empty
string | $key |
Definition at line 153 of file Encryption.php.
00154 { 00155 return $this->_getCrypt($key); 00156 }
$_crypt [protected] |
Definition at line 39 of file Encryption.php.
$_helper [protected] |
Definition at line 43 of file Encryption.php.