/** * Set the encryption key * * @param string $key * @return self * @throws Exception\InvalidArgumentException */ public function setKey($key) { try { $this->blockCipher->setKey($key); } catch (CryptException\InvalidArgumentException $e) { throw new Exception\InvalidArgumentException($e->getMessage()); } $this->encryption['key'] = $key; return $this; }
/** * Sets new encryption options * * @param string|array $options Encryption options * @return BlockCipher * @throws Exception\InvalidArgumentException */ public function setEncryption($options) { if (is_string($options)) { $this->blockCipher->setKey($options); $this->encryption['key'] = $options; return $this; } if (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options argument provided to filter'); } $options = $options + $this->encryption; if (isset($options['key'])) { $this->blockCipher->setKey($options['key']); } if (isset($options['algorithm'])) { try { $this->blockCipher->setCipherAlgorithm($options['algorithm']); } catch (CryptException\InvalidArgumentException $e) { throw new Exception\InvalidArgumentException("The algorithm '{$options['algorithm']}' is not supported"); } } if (isset($options['hash'])) { try { $this->blockCipher->setHashAlgorithm($options['hash']); } catch (CryptException\InvalidArgumentException $e) { throw new Exception\InvalidArgumentException("The algorithm '{$options['hash']}' is not supported"); } } if (isset($options['vector'])) { $this->setVector($options['vector']); } if (isset($options['key_iteration'])) { $this->blockCipher->setKeyIteration($options['key_iteration']); } $this->encryption = $options; return $this; }