http://www.perlmonks.org?node_id=410889

bronto has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks

We have a PHPChain database that, for reasons I can't explain here, we would like to dump into a CSV or Excel file

Of course, we could extract data from the underlying MySQL database with DBI and write it to, say, an Excel sheet with Spreadsheet::WriteExcel, but we need to decrypt the data stored in the database.

PHPChain encrypts and decrypts the data using these PHP functions:

function encrypt ($key, $data, $iv) { return mcrypt_encrypt (MCRYPT_BLOWFISH, $key, $data, MCRYPT_MO +DE_CBC, $iv); } function decrypt ($key, $data, $iv) { return mcrypt_decrypt (MCRYPT_BLOWFISH, $key, $data, MCRYPT_MO +DE_CBC, $iv); }

Do you know any way to decrypt the so-encrypted data with Perl?

Thanks a lot in advance

Ciao!
--bronto


In theory, there is no difference between theory and practice. In practice, there is.

Replies are listed 'Best First'.
Re: Decrypting PHP-encrypted data with Perl
by zejames (Hermit) on Nov 29, 2004 at 09:52 UTC
Re: Decrypting PHP-encrypted data with Perl
by gaal (Parson) on Nov 29, 2004 at 09:51 UTC
Re: Decrypting PHP-encrypted data with Perl
by zentara (Archbishop) on Nov 29, 2004 at 11:42 UTC
    In addition to zejames' suggestion, here is a sample outline of how to do it. Some experimentation may be needed.
    #!/usr/bin/perl use warnings; use strict; use Crypt::CBC; my $iv = '$KJh#(}q'; my $key = 'secret_foo'; ##----------- encryption ------------ my $cipher = Crypt::CBC->new( {'key' => $key, 'cipher' => 'Blowfish', 'padding' => 'standard', 'iv' => $iv, }); open(INF, "< wtest" ) || die; open(OUTF, ">$0.crypt") || die; $cipher->start('encrypting'); while (read(INF,my $buf, 1024 ) ) { print OUTF $cipher->crypt($buf); } print OUTF $cipher->finish; close(INF); close(OUTF); ##-------------------------- decryption -------------------- my $cipher1 = Crypt::CBC->new( { 'key' => $key, 'cipher' => 'Blowfish', 'padding'=> 'standard', 'iv' => $iv, }); open (INF1, "< $0.crypt") || die; open (OUTF1, ">$0.decrypt") || die; $cipher->start('decrypting'); while (read(INF1,my $buf, 1024 ) ) { print OUTF1 $cipher->decrypt($buf); } print OUTF1 $cipher->finish; close(INF1); close(OUTF1);

    I'm not really a human, but I play one on earth. flash japh
Re: Decrypting PHP-encrypted data with Perl
by DrHyde (Prior) on Nov 30, 2004 at 09:14 UTC
    Downvoted, because the author obviously didn't search the CPAN for the word "blowfish".

      It's a couple of years that I'm around here, and I know the basic rules, you the inquisitor.

      No, i didn't search for blowfish. But I searched for "PHP encryption" and found some hundreds of results (that means: nothing). Actually, I thought that it was using an encryption was someway intrinsic in PHP, and I hate PHP so much that I didn't even read the functions I pasted there (otherwise, maybe, I had done a search for at least "blowfish", since I didn't even know the existence of something called CBC)

      If you are going to do the inquisitor, at least do it wisely...

      Ciao!
      --bronto


      In theory, there is no difference between theory and practice. In practice, there is.
      and bronto has modules on cpan, unbeliveable