![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
31/01/2011, 02:51
|
![Avatar de aalleexx81](http://static.forosdelweb.com/customavatars/avatar329645_1.gif) | | | Fecha de Ingreso: noviembre-2009
Mensajes: 153
Antigüedad: 15 años, 3 meses Puntos: 0 | |
Respuesta: Encriptación Muchas gracias aagus. He cambiado el código y ya me funciona.
El código es el siguiente:
function encryptData($encryption_algorithm, $encryption_mode, $random_source, $encryption_key, $raw_data, $iv=null)
{
global $client_iv;
/* Open the cipher */
$td = mcrypt_module_open($encryption_algorithm, '', $encryption_mode, '');
/* Create the IV and determine the keysize length */
$client_iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), $random_source);
if ($iv != null)
$client_iv = $iv;
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5($encryption_key), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $client_iv);
/* Encrypt data */
$encrypted_data = mcrypt_generic($td, $raw_data);
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
//return array($client_iv, $encrypted_data);
return $encrypted_data;
}
/////////////////////////////////////////////////////////////////////
function decryptData($encryption_algorithm, $encryption_mode, $encryption_key, $client_iv, $encrypted_data)
{
/* Open the cipher */
$td = mcrypt_module_open($encryption_algorithm, '', $encryption_mode, '');
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5($encryption_key), 0, $ks);
/* Initialize encryption module for decryption */
mcrypt_generic_init($td, $key, $client_iv);
/* Decrypt encrypted string */
$decrypted_data = mdecrypt_generic($td, $encrypted_data);
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
/* Return string */
return trim($decrypted_data);
}
Saludos |