okay, here si the full script, the enc_cbc was a dif variable and I
rewrote it here and accidently included it but doesn't change the
error. Here is the full code
Here is the sample code
CODE - that doesn't decode
---------------------------------
#!/usr/bin/perl
use strict;
use Crypt::CBC;
my $encode1 = mycbc('enc','Key1','Data1');
my $decode1 = mycbc('dec','Key1',$encode1);
my $encode2 = mycbc('enc','Key2','Data1');
my $decode2 = mycbc('dec','Key2',$encode1);
print "Decode1: $decode1\nDecode2: $decode2\nEncode1: $encode1
\nEncode2: $encode2\n";
sub mycbc {
my @mycbc = @_;
$mycbc[3] = 'Blowfish' if (!(exists($mycbc[3])));
my $mycbc = Crypt::CBC->new(
-key => $mycbc[1],
-cipher => $mycbc[3],
-salt => 1,
-add_header => 0,
);
if ($mycbc[0] eq 'enc') {
return $mycbc->encrypt($mycbc[2]);
} else {
return $mycbc->decrypt($mycbc[2]);
}
}
---------------------------------
CODE - that doesn't decode
CODE - this doesn't either
---------------------------------
#!/usr/bin/perl
use strict;
use Crypt::CBC;
my $mycbc = Crypt::CBC->new(
-key => 'Key1',
-cipher => 'Blowfish',
-salt => 1,
-add_header => 0,
);
my $encode1 = $mycbc->encrypt('Data1');
undef($mycbc); #Just incase
my $mycbc2 = Crypt::CBC->new(
-key => 'Key1',
-cipher => 'Blowfish',
-salt => 1,
-add_header => 0,
);
my $decode1 = $mycbc2->decrypt($encode1);
print "Decode1: $decode1\nEncode1: $encode1\n";
---------------------------------
CODE - this doesn't either
So its not only a matter of new its more like making 2 objects one for
encrypting and one for decrypting. The decrypting doesnt work any more
it seems.
There is a way around it if I use:
CODE - this works
---------------------------------
#!/usr/bin/perl
use strict;
use Crypt::CBC;
my %mycbc;
my $encode1 = mycbc('enc','Key1','Data1');
my $decode1 = mycbc('dec','Key1',$encode1);
my $encode2 = mycbc('enc','Key2','Data2');
my $decode2 = mycbc('dec','Key2',$encode2);
my $encode3 = mycbc('enc','Key3','Data3');
my $decode3 = mycbc('dec','Key3',$encode3);
my $encode4 = mycbc('enc','Key4','Data4');
my $decode4 = mycbc('dec','Key4',$encode4);
my $encode5 = mycbc('enc','Key5','Data5');
my $decode5 = mycbc('dec','Key5',$encode5);
my $encode6 = mycbc('enc','Key','Data6');
my $decode6 = mycbc('dec','Key',$encode6);
print "Decode1: $decode1\nDecode2: $decode2\nDecode3: $decode3
\nDecode4: $decode4\nDecode5: $decode5\nDecode6: $decode6\nEncode1:
$encode1\nEncode2: $encode2\nEncode3: $encode3\nEncode4: $encode4\n";
sub mycbc {
my @mycbc = @_;
$mycbc[3] = 'Blowfish' if (!(exists($mycbc[3])));
if (exists($mycbc{$mycbc[3]}{$mycbc[1]})) {
} else {
$mycbc{$mycbc[3]}{$mycbc[1]} = Crypt::CBC->new(
-key => $mycbc[1],
-cipher => $mycbc[3],
-salt => 1,
-add_header => 0,
);
}
if ($mycbc[0] eq 'enc') {
return $mycbc{$mycbc[3]}{$mycbc[1]}->encrypt($mycbc[2]);
} else {
return $mycbc{$mycbc[3]}{$mycbc[1]}->decrypt($mycbc[2]);
}
}
---------------------------------
CODE - this works
Its fine and all but when using a server application, this just keeps
building up the hash.
[LDS - Thu Nov 17 18:26:59 2005]:
Show quoted text> Please send the entire script that demonstrates the bug. Your
> subroutine is making use of an array named @enc_cbc that is outside
the
Show quoted text> scope of the subroutine, and as far as I know the problem involves
your
Show quoted text> clobbering that variable somehow.