Hi,
One of the tasks I have to do needs me to encrypt something from PHP's side, and then decrypt it with Perl.
The PEAR module I've found which appeared to be suitable for my needs was Crypt_CBC. However, there must be something I'm doing wrong or do not understand, as I've been unable to achieve getting the correct results so far.
The code excerpts below are specifically intended for test purposes, as I've wanted to try it all out before applying it to my actual project's code.
First, here's my PHP code, with which I encrypt whatever is passed to a $text parameter (i.e. cryptTest.php?text=hello)
require_once('Crypt/CBC.php');
$key = "8326554161EB30EFBC6BF34CC3C832E7CF8135C1999603D4022C031FAEE";
$cipher = new Crypt_CBC($key, 'BLOWFISH');
$encrypted = $cipher->encrypt($text);
if (PEAR::isError($encrypted)) {
echo $encrypted->getMessage();
} else {
echo "ENCRYPTED STRING: " . $encrypted;
}
From that point, I copy whatever is echoed from this script (on my browser's output) and paste it in the $encrypted variable of my PERL script below:
use Crypt::CBC;
$encrypted = "RandomIVá´bp3Ó¯làK”Á(Û";
my $key = "8326554161EB30EFBC6BF34CC3C832E7CF8135C1999603D4022C031FAEE";
my $vector = "\0\0\0\0\0\0\0\0";
my $cipher = Crypt::CBC->new(
{'key' =>$key,
'cipher' => 'Blowfish',
'iv' => $vector,
'prepend_iv' => 0
});
my $plaintext = $cipher->decrypt($encrypted);
print $plaintext;
I've been trying out many things, like not specifying the IV on Perl side and such, but it kept giving me errors. This form is the only one with which I'm getting any output at all.
The result for the execution of the above, with original $text = "hello" is: Pñšîî7àÐŽZÊ&Rhello
What I find is that my original content is correctly decrypted, but not without adding a bunch of crap-characters before the part I want.
Can anyone point me to whatever I'm doing wrong and how I can resolve it?
Thanks a bunch.