|
Posted by veg_all on 10/20/28 11:59
here is some untested code i pasted below: basically the iv,
initailization vector is prepended to the encrypted data.
////////////////////////////////
function aes_encrypt ($input) {
global $key;
$td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
// iv = initiailization_vector;
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND );
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$encrypted_data = bin2hex ( $iv ) . bin2hex ( $encrypted_data );
return $encrypted_data;
} // end function
//////////////////////////////
function aes_decrypt ( $input ) {
global $key;
$iv = substr ( $input, 0, 32 );
$iv = pack ( H32, $iv );
$input = substr ( $input, 32, strlen ( $input ) );
$input =pack("H" . strlen ( $input ) , $input );
$td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
mcrypt_generic_init($td, $key, $iv);
$dec = mdecrypt_generic($td, $input );
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return trim ( $dec );
} // end function
//////////////////////////////
[Back to original message]
|