Reply to Re: Trouble decrypting data

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация