Skip Menu |

This queue is for tickets about the Crypt-CBC CPAN distribution.

Report information
The Basics
Id: 15846
Status: open
Priority: 0/
Queue: Crypt-CBC

People
Owner: LDS [...] cpan.org
Requestors: ask1about [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.15
Fixed in: (no value)



Subject: Problem when implementing multiple "new" inside
I was trying to make a function to make it easier in my case to decrypt and encrypt and I noticed a weird bug. CODE -------------- 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($enc_cbc[2]); } else { return $mycbc->decrypt($enc_cbc[2]); } } --------------- Running this function once works fine. The second time I run it though. 'decrypt' dies. encrypt still works(not sure if correctly though). I can work around it by useing the "$mycbc->passphrase()" and using different hashed values. But it onyl works once. Afterwards it doesnt.
Please send the entire script that demonstrates the bug. Your subroutine is making use of an array named @enc_cbc that is outside the scope of the subroutine, and as far as I know the problem involves your clobbering that variable somehow.
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.
If this was ever an issue, this has been fixed in the current version of the code. This bug should be closed. Note: In the original requestor's bug report, the code provided was not accurate. The code was initially encrypting the plaintext using key1 and placing it into scalar $encode1. Next, the code was decrypting $encode1 using key1 and placing it inside a scalar $decode1. Following this, the code encrypted the plaintext using key2 and placed it inside of scalar $encode2; however, when calling the decrypting function the code was trying to decrypt the ciphertext $encode1 that was initially encrypted with key1 using key2. When adjusted all worked well.