<?php
namespace App\Controllers;
use \App\Libraries\Complementos;
use \App\Libraries\Scripts;
use \App\Libraries\Error;
use \App\Libraries\Alertas;
use \App\Libraries\Pdf;


// use CodeIgniter\Controller;

class TestController extends BaseController
{
    public function __construct(){
	    
	}

    public function index()
    {
        $encryption = service('encrypter');
        // Encriptar un mensaje
        $data = '200';
        $encryptedData = $encryption->encrypt($data);

        // Convertir el texto encriptado a base64
        $base64EncryptedData = base64_encode($encryptedData);

        // Hacerlo "URL-safe" reemplazando caracteres
        $urlSafeBase64EncryptedData = strtr($base64EncryptedData, '+/', '-_');
        $urlSafeBase64EncryptedData = rtrim($urlSafeBase64EncryptedData, '=');

        echo "Texto encriptado (Base64 URL-safe): " . $urlSafeBase64EncryptedData . "<br>";

        // Convertir de vuelta a binario
        $decodedEncryptedData = strtr($urlSafeBase64EncryptedData, '-_', '+/');
        $decodedEncryptedData = base64_decode($decodedEncryptedData . '==');

        // Desencriptar el mensaje
        $decryptedData = $encryption->decrypt($decodedEncryptedData);
        echo "Texto desencriptado: " . $decryptedData;
        
    }
}