One of the tasks I need to perform is to encrypt something from the PHP side and then decrypt it using Perl.
The PEAR module, which seems to suit my needs, was Crypt_CBC. However, there must be something that I am doing wrong or do not understand, because so far I have not been able to achieve the correct results.
The code snippets below are specifically designed for testing, since I wanted to try all this before applying it to my actual project code.
Firstly, here is my PHP code, with which I encrypt everything, is passed to the $ 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 this point, I copy everything that is sent from this script (at the output of my browser) and paste it into 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 tried a lot of things, for example, without pointing IV to the Perl side, etc., but it kept giving me errors all the time. This form is the only one with which I generally get output.
The result to accomplish the above, with the original $ text = "hello": Pñšîî7àÐŽZÊ & Rhello
What I find is that my source content is correctly decrypted, but not without adding a bunch of shitty characters in front of the part that I want.
Can someone point me to what I am doing wrong and how can I solve it?
Thanks a lot.