Varien_Crypt_Mcrypt Class Reference

Inheritance diagram for Varien_Crypt_Mcrypt:

Varien_Crypt_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct (array $data=array())
 init ($key)
 encrypt ($data)
 decrypt ($data)
 __destruct ()

Protected Member Functions

 _reset ()


Detailed Description

Definition at line 35 of file Mcrypt.php.


Constructor & Destructor Documentation

__construct ( array data = array()  ) 

Constuctor

Parameters:
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     }


Member Function Documentation

_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

Parameters:
string $data encrypted string
Returns:
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

Parameters:
string $data source string
Returns:
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

Parameters:
string $key cipher private key
Returns:
Varien_Crypt_Mcrypt

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     }


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

Generated on Sat Jul 4 17:24:58 2009 for Magento by  doxygen 1.5.8