<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Opensslencryptdecrypt {

    public $encrypt_method = "AES-256-CBC";
    //these are test keys, you can be generate one at https://asecuritysite.com/encryption/keygen
    public $secret_key = 'LDKSAFH743SDF87SDBDS690SDFN78SD0'; //This is my secret key
    public $secret_iv = 'HJ4NJF76FGM8FNSW543F94NTG09DFN48'; //This is my secret iv
    public $output = false;

    function encrypt($string) {
        // hash
        $key = hash('sha256', $this->secret_key);
        // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
        $iv = substr(hash('sha256', $this->secret_iv), 0, 16);
        $output = openssl_encrypt($string, $this->encrypt_method, $key, 0, $iv);
        $output = base64_encode($output);
        return $output;
    }

    function decrypt($string) {
        // hash
        $key = hash('sha256', $this->secret_key);
        // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
        $iv = substr(hash('sha256', $this->secret_iv), 0, 16);
        $output = openssl_decrypt(base64_decode($string), $this->encrypt_method, $key, 0, $iv);
        return $output;
    }

  

}
