Пример #1
0
 /**
  * Sets the key.
  *
  * Rijndael supports five different key lengths
  *
  * @see setKeyLength()
  * @access public
  * @param string $key
  * @throws \LengthException if the key length isn't supported
  */
 function setKey($key)
 {
     switch (strlen($key)) {
         case 16:
         case 24:
         case 32:
             break;
         default:
             throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported');
     }
     parent::setKey($key);
 }
Пример #2
0
 /**
  * Test for engine validity
  *
  * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
  *
  * @see \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
  * @param int $engine
  * @access public
  * @return bool
  */
 function isValidEngine($engine)
 {
     if ($engine == self::ENGINE_OPENSSL) {
         if ($this->key_length != 16) {
             return false;
         }
         $this->cipher_name_openssl_ecb = 'bf-ecb';
         $this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode();
     }
     return parent::isValidEngine($engine);
 }
Пример #3
0
 /**
  * Setup the \phpseclib\Crypt\Common\SymmetricKey::ENGINE_MCRYPT $engine
  *
  * @see \phpseclib\Crypt\Common\SymmetricKey::_setupMcrypt()
  * @access private
  */
 function _setupMcrypt()
 {
     if (!isset($this->key)) {
         $this->setKey('');
     }
     parent::_setupMcrypt();
 }
Пример #4
0
 /**
  * Test for engine validity
  *
  * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
  *
  * @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
  * @param int $engine
  * @access public
  * @return bool
  */
 function isValidEngine($engine)
 {
     switch ($engine) {
         case self::ENGINE_OPENSSL:
             if ($this->block_size != 16) {
                 return false;
             }
             $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb';
             $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode();
             break;
         case self::ENGINE_MCRYPT:
             $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
             if ($this->key_length % 8) {
                 // is it a 160/224-bit key?
                 // mcrypt is not usable for them, only for 128/192/256-bit keys
                 return false;
             }
     }
     return parent::isValidEngine($engine);
 }