/** * {@inheritDoc} * * @throws \UnexpectedValueException */ public function render(AttributeEvent $event) { $cipherText = $event->getValue(); // The Amazon SDK base64 encodes binary strings before it sends data to // DynamoDB, but it does not base64 decode it after it retrieves the // data from DynamoDB. Therefore we have to check wheter it is encoded. if (preg_match(self::BASE64_REGEX, $cipherText)) { $cipherText = base64_decode($cipherText); if (false === $cipherText) { throw new \UnexpectedValueException('Error decoding data in the ' . $event->getAttribute() . ' attribute'); } } $plainText = $this->cipher->decrypt($cipherText); if (false === $plainText) { throw new \UnexpectedValueException('Error decrypting data in the ' . $event->getAttribute() . ' attribute: Invalid key'); } $event->setValue($plainText); }
/** * Decrypts a message. * * $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). * At least if the continuous buffer is disabled. * * @see Crypt_Base::encrypt() * @see Crypt_RC4::_crypt() * @access public * * @param String $ciphertext * * @return String $plaintext */ function decrypt($ciphertext) { if ($this->engine == CRYPT_MODE_MCRYPT) { return parent::decrypt($ciphertext); } return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT); }
/** * Decrypts a message. * * $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). * At least if the continuous buffer is disabled. * * @see Crypt_Base::encrypt() * @see self::_crypt() * @access public * @param string $ciphertext * @return string $plaintext */ function decrypt($ciphertext) { if ($this->engine != CRYPT_ENGINE_INTERNAL) { return parent::decrypt($ciphertext); } return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT); }
/** * Decrypts a message. * * Mostly a wrapper for Crypt_Base::decrypt, with some additional OpenSSL handling code * * @see self::encrypt() * @access public * @param string $ciphertext * @return string $plaintext */ function decrypt($ciphertext) { if ($this->engine == CRYPT_ENGINE_OPENSSL) { $temp = $this->key; $this->key = $this->orig_key; $result = parent::decrypt($ciphertext); $this->key = $temp; return $result; } return parent::decrypt($ciphertext); }