public function encrypt($data)
    {
        $iv = openssl_random_pseudo_bytes($this->getSize());

        $value = openssl_encrypt(serialize($data), $this->method, $this->key, 0, $iv);

        $mac = $this->hash($iv = base64_encode($iv), $value);

        return base64_encode(json_encode(compact('iv', 'value', 'mac')));
    }