Script using Crypt::CBC encryption/decryption

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vermarajeev
    New Member
    • Aug 2006
    • 180

    Script using Crypt::CBC encryption/decryption

    Hello friends,

    I am new to Perl scripts.
    Please help me out....

    I am using crypt::CBC to encrypt my files...

    during decryption process it goes through the code as follows
    [CODE=perl]
    if ($header_mode eq 'salt') {
    my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
    croak "Ciphertext does not begin with a valid header for 'salt' header mode" unless defined $salt;
    $self->{salt} = $salt; # new salt
    substr($$input_ stream,0,16) = '';
    my ($key,$iv) = $self->_salted_key_an d_iv($self->{passphrase},$ salt);
    $self->{iv} = $self->{civ} = $iv;
    $self->{key} = $key;
    }
    [/CODE]

    [CODE=perl]
    my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
    [/CODE]

    Can anybody tell me what the above instruction means....

    [CODE=perl]
    sub _salted_key_and _iv {
    my $self = shift;
    my ($pass,$salt) = @_;

    croak "Salt must be 8 bytes long" unless length $salt == 8;

    my $key_len = $self->{keysize};
    my $iv_len = $self->{blocksize};

    my $desired_len = $key_len+$iv_le n;

    my $data = '';
    my $d = '';

    while (length $data < $desired_len) {
    $d = md5($d . $pass . $salt);
    $data .= $d;
    }
    return (substr($data,0 ,$key_len),subs tr($data,$key_l en,$iv_len));
    }
    [/CODE]

    How are they retrieve the password and the iv

    Thanks,
    Rajeev
    Last edited by miller; Sep 3 '07, 05:45 PM. Reason: Code Tag and ReFormatting
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Rajeev.

    I'm going to go ahead and move this thread to the Perl forum, where our resident Experts will be better able to help you out.

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Originally posted by vermarajeev
      [CODE=perl]
      my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
      [/CODE]

      Can anybody tell me what the above instruction means....
      Rajeev,

      It assigns $salt to the 8 characters after Salted__ from the string $$input_stream.

      I suggest that you read Crypt::CBC instead of simply using someone else's script. You'll find more clear usage description in there, and they are also 3 example scripts included in the distribution. You'll find links to them at the bottom of the cpan doc.

      - Miller

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Originally posted by miller
        Rajeev,

        It assigns $salt to the 8 characters after Salted__ from the string $$input_stream.

        I suggest that you read Crypt::CBC instead of simply using someone else's script. You'll find more clear usage description in there, and they are also 3 example scripts included in the distribution. You'll find links to them at the bottom of the cpan doc.

        - Miller
        Welcome back miller! How was your trip?

        Jeff

        Comment

        Working...