469,268 Members | 962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

Script using Crypt::CBC encryption/decryption

180 100+
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
Expand|Select|Wrap|Line Numbers
  1. if ($header_mode eq 'salt') {
  2.     my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
  3.     croak "Ciphertext does not begin with a valid header for 'salt' header mode" unless defined $salt;
  4.     $self->{salt} = $salt;          # new salt
  5.     substr($$input_stream,0,16) = '';
  6.     my ($key,$iv) = $self->_salted_key_and_iv($self->{passphrase},$salt);
  7.     $self->{iv} = $self->{civ}  = $iv;
  8.     $self->{key}  = $key;
  9. }
  10.  
Expand|Select|Wrap|Line Numbers
  1. my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
  2.  
Can anybody tell me what the above instruction means....

Expand|Select|Wrap|Line Numbers
  1. sub _salted_key_and_iv {
  2.     my $self = shift;
  3.     my ($pass,$salt)  = @_;
  4.  
  5.     croak "Salt must be 8 bytes long" unless length $salt == 8;
  6.  
  7.     my $key_len = $self->{keysize};
  8.     my $iv_len  = $self->{blocksize};
  9.  
  10.     my $desired_len = $key_len+$iv_len;
  11.  
  12.     my $data  = '';
  13.     my $d = '';
  14.  
  15.     while (length $data < $desired_len) {
  16.         $d = md5($d . $pass . $salt);
  17.         $data .= $d;
  18.     }
  19.     return (substr($data,0,$key_len),substr($data,$key_len,$iv_len));
  20. }
  21.  
How are they retrieve the password and the iv

Thanks,
Rajeev
Sep 3 '07 #1
3 6919
pbmods
5,821 Expert 4TB
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.
Sep 3 '07 #2
miller
1,089 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. my ($salt) = $$input_stream =~ /^Salted__(.{8})/s;
  2.  
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
Sep 3 '07 #3
numberwhun
3,503 Expert Mod 2GB
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
Sep 3 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jerry Maguire | last post: by
2 posts views Thread by Edward W. | last post: by
34 posts views Thread by kpg | last post: by
1 post views Thread by josh.kuo | last post: by
2 posts views Thread by vermarajeev | last post: by
9 posts views Thread by Alan M Dunsmuir | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.