Making Perl Crypt::CBC work with PHP mcrypt_cbc()



First of all, I know this is a PHP news group, so my question may not
be completely appropriate here since it involves some perl.

I have read this post that dealt with a similar problem that I am
having now:
http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thre...

Summary of my problem:
I need to have a perl script that encrypts a string, write the output
to a file,
and then have a PHP script read the file, and decrypts it. I took most
of the code from this URL:

http://us2.php.net/manual/en/function.mcrypt-cbc.php

Below is my perl code used to encrypt

<perl>
#!/usr/bin/perl
use MIME::Base64;
use Crypt::CBC;
my $key = '012345678901234567890123456789';
my $iv = '12345678';
my $text = 'This is my plain text';
$cipher = Crypt::CBC->new({'literal_key' => 0,
'key' => $key,
'cipher' => 'Blowfish',
'iv' => $iv,
'padding' => 'null',
'prepend_iv' => 0});
$encrypted = $cipher->encrypt($text);
$encoded = encode_base64($encrypted);
open(FILE, ">encrypt.txt");
print FILE $encoded;
close(FILE);
</perl>

And here's my PHP script used to decrypt:

<?php
$key = '012345678901234567890123456789';
$iv = '12345678';
$lines = file('encrypt.txt');
$encoded = '';
foreach ($lines as $line) {
$encoded .= $line;
}

$encrypted = base64_decode($encoded);
$decrypted = mcrypt_cbc(MCRYPT_BLOWFISH, $key, $bin_encrypted,
MCRYPT_DECRYPT, $iv);
echo "decrypted : [$decrypted]";
exit();
?>

But the decryption doesn't seem to work... If I printed out the base64
encoded strings, they match. So I suspect it's something that I did
not do correctly either in the encryption or decryption of the message.

Any help is appreciated.

.



Relevant Pages

  • Making Perl Crypt::CBC work with PHP mcrypt_cbc()
    ... be completely appropriate here since it involves some PHP. ... I need to have a perl script that encrypts, write the output to a file, ... But the decryption doesn't seem to work... ...
    (comp.lang.perl.misc)
  • Re: What are the differences between Perl and PHP when handling with Web pages
    ... What are the differences between Perl and PHP? ... anyway for the sake of good programming practice. ... I end up using PHP more for web development than PHP. ...
    (perl.beginners)
  • Re: Can a Perl Programmer Pick up PHP quickly?
    ... PHP is not easier compared to Perl. ... a language with fewer features is going to be easier to ... You can't call documentation guessed after the source not good ...
    (comp.lang.perl.misc)
  • Re: Face lift survey
    ... But PHP, I think, integrates html code a better way. ... you still have to do a perl script and then put ... Perl CGI programming! ...
    (perl.beginners)
  • Re: Coverting perl to php
    ... I am bout ready to convert it to php but wonder if there are ... but there's nothing to match a good perl person porting their ... The reason for the rewrite is because a large chunk of the ancilary ... code to talk to the database, recreating what they did, and having 2 ...
    (comp.lang.php)