Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Crypt::CBC and varying the key

by Anonymous Monk
on Mar 10, 2006 at 18:41 UTC ( #535780=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem: I'm useing Crypt::CBC to encrypt some data. But the first datablock is to be encrypted with another key than the next. I need to encrypt the "next" datablock with the same IV the first *left of*. How can I achieve this?

Comment on Crypt::CBC and varying the key
Re: Crypt::CBC and varying the key
by jimbojones (Friar) on Mar 10, 2006 at 20:33 UTC
    Hi

    If I understand you correctly, you're not doing CBC (cipher block chaining). See this article in Wikipedia. If you are doing CBC, you only need a key and one initialiation vector (IV). The "chaining" is to use the previous block as the IV for the next block before encrypting with the key.

    CBC allows you to chain together a message that is bigger than the block size as one unit. Is this not what you want?

    Hope this helps, J
      Yes, I know what CBC is. I *use* CBC. But I want to crypt 2 blocks (not in the sense of the cipher but say strings) of data. The second block has another key from the first one. But the IV is carried over. This is to get two levels of access to the data.
        Hi

        It looks like you'll have to modify CBC.pm. In my version (2.14), the 'finish' method deletes the current IV.
        delete $self->{'civ'}; delete $self->{'buffer'}; return $result; }
        You'll have to prevent that from happening, and then add a method to return the current (last) IV, instead of the initial IV
        sub get_civ { return $self->{civ}; }
        I have no idea if or how this affects the security of the two messages.

        Hope this helps, J

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://535780]
Approved by spiritway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-09-19 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls