Forum Moderators: coopster
perl code is as follows :
use Crypt::CBC;
$key = "SuperFreak";
$action = shift;
$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);
}
BlakMonk
mdecrypt_generic[php.net] there's a user-contributed comment with code for encrypting and decrypting stuff. It might inspire you.
Yes, it does inspire me, but what they are using is ecb, other examples use fcb... but nothing so far uses cbc...
All I have go right now is this (below), and still no go....
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";
}
Blakmonk