Troubling warnings using PHP decrypt functions



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

.



Relevant Pages

  • Re: [PHP] Converting PHP code to C#?
    ... I've done it in reverse - something encrypted in .NET and then decrypted in PHP ... You need the mcrypt extension installed. ... You can issue this single line of code to decrypt: ... with no encoding, get it to work, then add on encoding and decoding on ...
    (php.general)
  • Re: phpmyadmins blowfish / mcrypt
    ... > I'm writing an app that will use blowfish encryption.. ... > PHP's mcrypt will be used if available. ... if I encrypt with blowfish.php and decrypt with mcrypt: ... Only getting partial output suggests that it may be a string termination ...
    (comp.lang.php)
  • Re: mcrypt not working
    ... > key, then choose from a dropdown menu of encryption/decryption cyphers, ... decrypt). ... except the mcrypt command doesn't work. ...
    (comp.lang.php)
  • Decryption Question
    ... chase...from what I've read there are two functions used to encrypt and ... decrypt data, here is part of that article to decrypt data in a select ... OPEN SYMMETRIC KEY TestTableKey ...
    (microsoft.public.sqlserver.security)
  • exporting session key
    ... 3DES session key, then encrypt and decrypt data. ...
    (microsoft.public.platformsdk.security)