Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/08/2010, 06:08
mikote2000
 
Fecha de Ingreso: septiembre-2008
Mensajes: 26
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Pasar variable GET encriptado con algoritmo de semilla

He usado un paso intermedio, el IV y la key las guardo como variable de sesión sólo calculandolas una vez. Luego modifico las cadenas para evitar las cadenas con + y simbolos no permitidos y posteriormente recojo y hago la inversaa.

Código PHP:
<?php
function encode_this($message$key=LLAVE) {
    if(!empty(
$message)){
        
#
        
$td mcrypt_module_open('rijndael-256''''ofb''');
    
#
     
    #
        /* Create the IV and determine the keysize length, use MCRYPT_RAND
    #
         * on Windows instead */
    #
        
$ks mcrypt_enc_get_key_size($td);
        
        if(!isset(
$_SESSION[IV])){
    
#
            
$iv mcrypt_create_iv($ksMCRYPT_RAND);
            
$_SESSION[IV] = $iv;
        }
        else{
            
$iv $_SESSION[IV];
        }
    
#
     
    #
        /* Create key */
        
        
if(!isset($_SESSION[CLAVE])){
    
#
            
$key substr(md5($key), 0$ks);
            
$_SESSION[CLAVE] = $key;
        
        }
        else{
            
$key $_SESSION[CLAVE];
        }
    
#
     
    #
        /* Intialize encryption */
    #
        
mcrypt_generic_init($td$key$iv);
    
#
     
    #
        /* Encrypt data */
    #
        
$encrypted mcrypt_generic($td$message);
    
#
     
    #
        /* Terminate encryption handler */
    #
        
mcrypt_generic_deinit($td);
    
#
        
mcrypt_module_close($td);
    
#
     
    #
        
return strtr(base64_encode($encrypted), '+/=''-_,');
     }


function 
decode_this($encrypted) {
    if(!empty(
$encrypted)){
        
#
        
$encrypted base64_decode(strtr($encrypted'-_,''+/='));
        
$td mcrypt_module_open('rijndael-256''''ofb''');
    
#
     
    #
        /* Initialize encryption module for decryption */
    #
        
mcrypt_generic_init($td$_SESSION[CLAVE], $_SESSION[IV]);
    
#
     
    #
        /* Decrypt encrypted string */
    #
        
$decrypted mdecrypt_generic($td$encrypted);
    
#
     
    #
        /* Terminate decryption handle and close module */
    #
        
mcrypt_generic_deinit($td);
    
#
        
mcrypt_module_close($td);
    
#
     
    #
        /* Show string */
    #
        
return trim($decrypted);
     }
}  
?>
Gracias por tu ayuda.

Saludos