<file_sep><?php
include "AESEncryptDecrypt.php";

// Como usar las funciones para encriptar y desencriptar.

$aes = new AESEncryptDecrypt();
$data = "q";
$en = $aes->encrypt($data);
$des = $aes->decrypt($en);
echo 'Dato encriptado: '. $en . '<br>';
echo 'Dato desencriptado: '. $des . '<br>';
?><file_sep><?php

    class AESEncryptDecrypt {

        public $password = '<PASSWORD>';
        public $method = 'aes-256-cbc';
        public $strong = false;
        public $iv_length;
        public $iv;

        
        /**
         * Función que encrypta 
         */
        public function encrypt($data) {  
            $this->iv_length = openssl_cipher_iv_length($this->method);
            $this->iv = openssl_random_pseudo_bytes($this->iv_length, );
            return base64_encode(openssl_encrypt($data, $this->method, $this->password, true, $this->iv)); 
        }

        /**
         * Función que desencrypta 
         */
        public function decrypt($data){ 
            $this->iv_length = openssl_cipher_iv_length($this->method);
            $this->iv = openssl_random_pseudo_bytes($this->iv_length, $this->strong);
            return openssl_decrypt(base64_decode($data), $this->method, $this->password, true, $this->iv); 
        }
    
    }
?><file_sep><?php

    class AESEncrypt {

        public $password;
        public $method;
        public $strong;
        public $iv_length;
        public $iv;

        public __construc(){
            this->$password = "<PASSWORD>";
            this->$method = 'aes-256-cbc';
            this->$strong = false;
            this->$iv_length = openssl_cipher_iv_length(this->$method);
            this->$iv = openssl_random_pseudo_bytes(this->$iv_length, this->$strong);
        }

        function encrypt($data) { return base64_encode(openssl_encrypt($data, $method, $password, true, $iv)); }

        function decrypt($data){ return openssl_decrypt(base64_decode($enc_data), $method, $password, true, $iv); }


    }
?>