/** * {@inheritDoc} * * @throws \UnexpectedValueException */ public function render(AttributeEvent $event) { $data = base64_decode($event->getValue()); if (false === $data) { throw new \UnexpectedValueException('Error decoding data in the ' . $event->getAttribute() . ' attribute'); } $event->setValue($data); }
/** * {@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); }