Hi all,

I have this huge problem. I (php script) need to be - compatible - with some other perl scripts.

The perl scrypts use the sub below.

sub Cryptage
{
use Crypt::CBC;
my $key = "SuperFreak";
my $action = shift;
my $string = shift;

my $c = new Crypt::CBC($key,"IDEA");
if ($action == 1) { #- crypt
return $c->encrypt_hex($string);
} else { #- decrypt
return $c->decrypt_hex($string);
}
}


I need to create and read the same output with php, so far I got what is below :


function Cryptage($plain_text,$action)
{
$key = "SuperFreak";

$td = mcrypt_module_open('des', '', 'cbc', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

if (mcrypt_generic_init($td, $key, $iv)!= -1) {
if ($action == 1) { #- encryption
#return bin2hex(mcrypt_cbc($td, $data, MCRYPT_ENCRYPT, $iv));
$c_t = bin2hex(mcrypt_generic($td, $plain_text));
} else { #- decryption
#return trim(mcrypt_decrypt($td, $key, pack("H*",$plain_text), MCRYPT_ENCRYPT,$iv));
$c_t = trim(mdecrypt_generic($td, $c_t));
}

mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $c_t;
}else{
return "ERROR IN ENCRYPTION";
}
}


it doen't match...

can anyone help ?

- I cannot use a system call to create/read the crypt
- I cannot change the running perl scripts

Thanx in advance
BlakMonk