![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
11/04/2014, 09:18
|
| | Fecha de Ingreso: abril-2010
Mensajes: 267
Antigüedad: 14 años, 10 meses Puntos: 1 | |
Respuesta: ¿Crear un encriptador propio? Holaaa :) Muchas gracias por las respuestas, he probado tu ncodigo y he conseguido otro similar, el otro es el que tiene las "//", y me llama la atención que ninguno de los dos me funcione correctamente, supongo que el fallo es mío, ¿Dónde tengo el fallo? :/ Cita: <?php
function encriptador($string, $funcion) {
$key = "ytrwt674ytrw87th86rgw4t4f6d4t4r6";
if($funcion!=1 || $funcion!=2) {
$funcion = 1;
}
if($funcion==1) {
//$result = ”;
//for($i=0; $i<strlen($string); $i++) {
// $char = substr($string, $i, 1);
// $keychar = substr($key, ($i % strlen($key))-1, 1);
// $char = chr(ord($char)+ord($keychar));
// $result.=$char;
//}
//return base64_encode($result);
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_ 256, $key, $string, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAE L_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
} elseif($funcion==2) {
//$result = ”;
//$string = base64_decode($string);
//for($i=0; $i<strlen($string); $i++) {
// $char = substr($string, $i, 1);
// $keychar = substr($key, ($i % strlen($key))-1, 1);
// $char = chr(ord($char)-ord($keychar));
// $result.=$char;
//}
//return base64_decode($result);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($string), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAE L_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
}
echo encriptador("LA CADENA A ENCRIPTAR",1);
echo '<br>';
echo encriptador("4oCdsKmUtbSusLuvlKiMt8GuwL29u7HF",2);
?> Y me da esto: Cita: Texto encriptado:
locXPzLOoHU/ARqg5vqT+dw1MIm7/BVbO0ZYANeQdUs=
Texto desencriptado:
wS7UMKvRd1gu32NhJuAf3wdktykza6YGp0mb7n/Jnf8= ¡Un Saludo! :) |