Ejemplo n.º 1
0
 /**
  * Set the key to use for the cipher
  *
  * @param string $key The key to use
  *
  * @throws InvalidArgumentException If the key is not the correct size
  * @return void
  */
 public function setKey($key)
 {
     switch ($this->cipher) {
         case 'rijndael-128':
         case 'rijndael-192':
         case 'rijndael-256':
             if (!in_array(strlen($key), array(16, 20, 24, 28, 32))) {
                 throw new \InvalidArgumentException(sprintf('The supplied key block is in the valid sizes [%d:%s]', strlen($key), '16, 20, 24, 28, 32'));
             }
             $this->keySize = strlen($key);
         default:
             parent::setKey($key);
     }
 }
Ejemplo n.º 2
0
 /**
  * Construct the instance for the supplied cipher name
  *
  * @param string $cipher The cipher to implement
  *
  * @return void
  * @throws InvalidArgumentException if the cipher is not supported
  */
 public function __construct($cipher)
 {
     parent::__construct($cipher);
     list(, $bits) = explode('-', $cipher, 2);
     $this->setBlockSize($bits);
     $this->setKeySize($bits);
     static::init();
 }