Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Is Crypt::CBC really working?

by esskar (Deacon)
on Feb 16, 2005 at 03:52 UTC ( #431424=perlquestion: print w/replies, xml ) Need Help??

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

i have the following piece of code.
#!/usr/bin/perl use strict; use Crypt::CBC (); use Digest::SHA (); my $pass = 'test'; my $text = 'hutzelhutzelhutzel'; my $key = &Digest::SHA::sha512_hex($pass); print "Key1: $key\n"; my $cbc = Crypt::CBC->new( 'cipher' => 'DES', 'key' => $key, 'regenerate_key' => 0, 'prepend_iv' => 0, ); my $cipher = $cbc->encrypt($text); print "Cipher: $cipher\n"; $cbc = Crypt::CBC->new( 'cipher' => 'DES', 'key' => $key, 'regenerate_key' => 0, 'prepend_iv' => 0, ); print "Plain1: ", $cbc->decrypt($cipher), "\n"; # new password $pass = 'test2'; $key = &Digest::SHA::sha512_hex($pass); print "Key2: $key\n"; $cbc = Crypt::CBC->new( 'cipher' => 'DES', 'key' => $key, 'regenerate_key' => 0, 'prepend_iv' => 0, ); print "Plain2: ", $cbc->decrypt($cipher), "\n";
As you can see, i'm changing the password between the first and second decryption but the results (Plain1, Plain2) are both the same and both are equal to $text. Am I missing something?

This is perl, v5.8.4 built for MSWin32-x86-multi-thread
$Crypt::CBC::VERSION eq '2.12'

Replies are listed 'Best First'.
Re: Is Crypt::CBC really working?
by esskar (Deacon) on Feb 16, 2005 at 04:10 UTC
    oh no

    the CBC->new takes a hash-ref and not a hash
    sorry for my stupidy

    time to go to bed!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://431424]
Approved by K_M_McMahon
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-03-22 02:28 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.