<?php

namespace buckhill\encrypter;

class Encrypter extends AbstractEncrypter implements EncrypterInterface
{
    public function decrypt($string)
    {
        $result = openssl_decrypt($string, $this->method, $this->secret, true, $this->iv);

        if(false === $result)
        {
            throw new \Exception("Error occurred while decrypting. Error reported: ". openssl_error_string());
        }

        return $result;
    }

    public function encrypt($string)
    {
        return openssl_encrypt($string, $this->method, $this->secret, true, $this->iv);
    }
}