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')));
    }
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')));
    }
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' ) ) ) ; }
To encrypt data

@param $data

@return string
To encrypt data