PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Encrypting with Crypt_CBC, Decrypting with Perl's CBC

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Encryption
View previous topic :: View next topic  
Author Message
mduchesneau



Joined: 17 Mar 2009
Posts: 1
Location: Montral, QC, Canada

PostPosted: Tue Mar 17, 2009 3:54 pm    Post subject: Encrypting with Crypt_CBC, Decrypting with Perl's CBC Reply with quote

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 intented 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)

Code:

<?php

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:

Code:


use Crypt::CBC;

$encrypted = "RandomIVbp3ӯlK(";
my $key = "8326554161EB30EFBC6BF34CC3C832E7CF8135C1999603D4022C031FAEE";
my $vector = "\0\0\0\0\0\0\0\0";
#my $vector = 'abcdefgh';

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: P7?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.
_________________
---
Mathieu
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Encryption All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement