|
Posted by laredotornado@zipmail.com on 10/19/69 11:59
Hi,
I'm using PHP 4.4.4. Using code from this newsgroup, I have a decrypt
function, trying to decrypt data (encryped using a corresponding mcrypt
function). What am I doing wrong? These are the warnings, generated
from the decrypt function (lines are marked in the function, code
follows)
Warning: pack() [function.pack]: Type H: not enough characters in
string in /usr/local/apache2/htdocs/refillingstation/form_fns.php on
line 173
Warning: mcrypt_generic_init(): Iv size incorrect; supplied length: 4,
needed: 16 in /usr/local/apache2/htdocs/refillingstation/form_fns.php
on line 180
Any guidance is greatly appreciated to eliminate these warnings.
function decryptData( $input ) {
$iv = substr ( $input, 0, 32 );
$iv = pack ( H32, $iv ); // line 173
$input = substr ( $input, 32, strlen ( $input ) );
$input =pack("H" . strlen ( $input ) , $input );
$td = mcrypt_module_open('rijndael-128', '', 'cbc',
'');
mcrypt_generic_init($td, ENCRYPTION_KEY, $iv);
// line 180
$dec = mdecrypt_generic($td, $input );
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return trim ( $dec );
}
function encryptData($input) {
$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, ENCRYPTION_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
[Back to original message]
|