Código PHP:
<?php
$stuff="TEST";
$key="XiTo74dOO09N48YeUmuvbL0E";
function nl() {
echo "<br/> \n";
}
$iv = mcrypt_create_iv (mcrypt_get_block_size (MCRYPT_TripleDES, MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
// Encrypting
function encrypt($string, $key) {
$enc = "";
global $iv;
$enc=mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_ENCRYPT, $iv);
return base64_encode($enc);
}
// Decrypting
function decrypt($string, $key) {
$dec = "";
$string = trim(base64_decode($string));
global $iv;
$dec = mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_DECRYPT, $iv);
return $dec;
}
/*
$encrypted = encrypt($stuff, $key);
$decrypted = decrypt($encrypted, $key);
$decrypted=ereg_replace("[^A-Za-z0-9]", "", $decrypted);
echo "Encrypted is ".$encrypted . nl();
echo "Decrypted is ".$decrypted . nl();*/
?>
Código PHP:
<?
include("inc/inc-encriptar.php");
$cadena="FUNCIONA";
$cadena_encriptada = encrypt($cadena, $key);
?>
<a href="test-encriptar.php?cadena_encriptada=<?=$cadena_encriptada?>">enviar (<?=$cadena?>)</a>
Código PHP:
<?
include("inc/inc-encriptar.php");
$cadena=$_GET['cadena_encriptada'];
echo $cadena."<br />";
$cadena=decrypt($cadena,$key);
echo $cadena."<br />";
$cadena=ereg_replace("[^A-Za-z0-9]", "", $cadena);
echo $cadena."<br />";
?>