/** * {@inheritdoc} */ public function encrypt($value) { try { $ciphertext = Crypto::Encrypt($value, $this->keyReader->read()); if (!$this->binaryOutput) { $ciphertext = base64_encode($ciphertext); if ($ciphertext === false) { throw new SymmetricEncryptionException('Cannot encode message to base64'); } } return $ciphertext; } catch (CryptoTestFailedException $e) { throw SymmetricEncryptionException::cryptoTestFailed($e); } catch (CannotPerformOperationException $e) { throw SymmetricEncryptionException::cannotPerformOperation($e); } }
/** * {@inheritdoc} */ public function decrypt($value) { try { if (!$this->binaryOutput) { $value = base64_decode($value, true); if ($value === false) { throw SymmetricEncryptionException::invalidCiphertext(new InvalidCiphertextException()); } } return Crypto::Decrypt($value, $this->keyReader->read()); } catch (InvalidCiphertextException $e) { throw SymmetricEncryptionException::invalidCiphertext($e); } catch (CryptoTestFailedException $e) { throw SymmetricEncryptionException::cryptoTestFailed($e); } catch (CannotPerformOperationException $e) { throw SymmetricEncryptionException::cannotPerformOperation($e); } }