Mage_Core_Model_Encryption Class Reference

List of all members.

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


Detailed Description

Definition at line 34 of file Encryption.php.


Member Function Documentation

_getCrypt ( key = null  )  [protected]

Instantiate crypt model

Parameters:
string $key
Returns:
Varien_Crypt_Mcrypt

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

Parameters:
string $data
Returns:
string

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

Parameters:
string $data
Returns:
string

Definition at line 131 of file Encryption.php.

00132     {
00133         return base64_encode($this->_getCrypt()->encrypt((string)$data));
00134     }

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

Parameters:
string $password
mixed $salt
Returns:
string

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

Parameters:
string $data
Returns:
string

Definition at line 83 of file Encryption.php.

00084     {
00085         return md5($data);
00086     }

setHelper ( helper  ) 

Set helper instance

Parameters:
Mage_Core_Helper_Data $helper
Returns:
Mage_Core_Model_Encryption

Definition at line 51 of file Encryption.php.

00052     {
00053         $this->_helper = $helper;
00054         return $this;
00055     }

validateHash ( password,
hash 
)

Validate hash against hashing method (with or without salt)

Parameters:
string $password
string $hash
Returns:
bool
Exceptions:
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

Parameters:
string $key
Returns:
Varien_Crypt_Mcrypt

Definition at line 153 of file Encryption.php.

00154     {
00155         return $this->_getCrypt($key);
00156     }


Member Data Documentation

$_crypt [protected]

Definition at line 39 of file Encryption.php.

$_helper [protected]

Definition at line 43 of file Encryption.php.


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

Generated on Sat Jul 4 17:23:57 2009 for Magento by  doxygen 1.5.8