Beispiel #1
0
 /**
  * Default Constructor.
  *
  * Determines whether or not the mcrypt extension should be used.
  *
  * $mode could be:
  *
  * - CRYPT_AES_MODE_ECB
  *
  * - CRYPT_AES_MODE_CBC
  *
  * - CRYPT_AES_MODE_CTR
  *
  * - CRYPT_AES_MODE_CFB
  *
  * - CRYPT_AES_MODE_OFB
  *
  * If not explictly set, CRYPT_AES_MODE_CBC will be used.
  *
  * @see Crypt_Rijndael::Crypt_Rijndael()
  * @see Crypt_Base::Crypt_Base()
  * @param optional Integer $mode
  * @access public
  */
 function __construct($mode = CRYPT_AES_MODE_CBC)
 {
     parent::__construct($mode);
 }
Beispiel #2
0
 /**
  * Default Constructor.
  *
  * Determines whether or not the mcrypt extension should be used. $mode should only, at present, be
  * CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC. If not explictly set, CRYPT_AES_MODE_CBC will be used.
  *
  * @param
  *        	optional Integer $mode
  * @return Crypt_AES
  * @access public
  */
 function __construct($mode = CRYPT_AES_MODE_CBC)
 {
     if (!defined('CRYPT_AES_MODE')) {
         switch (true) {
             case extension_loaded('mcrypt'):
                 // i'd check to see if aes was supported, by doing in_array('des', mcrypt_list_algorithms('')),
                 // but since that can be changed after the object has been created, there doesn't seem to be
                 // a lot of point...
                 define('CRYPT_AES_MODE', CRYPT_AES_MODE_MCRYPT);
                 break;
             default:
                 define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
         }
     }
     switch (CRYPT_AES_MODE) {
         case CRYPT_AES_MODE_MCRYPT:
             switch ($mode) {
                 case CRYPT_AES_MODE_ECB:
                     $this->paddable = true;
                     $this->mode = MCRYPT_MODE_ECB;
                     break;
                 case CRYPT_AES_MODE_CTR:
                     // ctr doesn't have a constant associated with it even though it appears to be fairly widely
                     // supported. in lieu of knowing just how widely supported it is, i've, for now, opted not to
                     // include a compatibility layer. the layer has been implemented but, for now, is commented out.
                     $this->mode = 'ctr';
                     // $this->mode = in_array('ctr', mcrypt_list_modes()) ? 'ctr' : CRYPT_AES_MODE_CTR;
                     break;
                 case CRYPT_AES_MODE_CFB:
                     $this->mode = 'ncfb';
                     break;
                 case CRYPT_AES_MODE_OFB:
                     $this->mode = MCRYPT_MODE_NOFB;
                     break;
                 case CRYPT_AES_MODE_CBC:
                 default:
                     $this->paddable = true;
                     $this->mode = MCRYPT_MODE_CBC;
             }
             $this->debuffer = $this->enbuffer = '';
             break;
         default:
             switch ($mode) {
                 case CRYPT_AES_MODE_ECB:
                     $this->paddable = true;
                     $this->mode = CRYPT_RIJNDAEL_MODE_ECB;
                     break;
                 case CRYPT_AES_MODE_CTR:
                     $this->mode = CRYPT_RIJNDAEL_MODE_CTR;
                     break;
                 case CRYPT_AES_MODE_CFB:
                     $this->mode = CRYPT_RIJNDAEL_MODE_CFB;
                     break;
                 case CRYPT_AES_MODE_OFB:
                     $this->mode = CRYPT_RIJNDAEL_MODE_OFB;
                     break;
                 case CRYPT_AES_MODE_CBC:
                 default:
                     $this->paddable = true;
                     $this->mode = CRYPT_RIJNDAEL_MODE_CBC;
             }
     }
     if (CRYPT_AES_MODE == CRYPT_AES_MODE_INTERNAL) {
         parent::__construct($this->mode);
     }
 }