in reply to Crypt CBC

Why do you pack and unpack the ciphertext by hand? Why not use encrypt_hex() and decrypt_hex()? I suspect your problem is with the pack()/unpack() not with CBC.

When you say, unpack("H16", "a" x 27); you only unpack the first 16 bytes, or words or something like that. I think you want unpack("H*", $ciphertext); but more than that, I think you want $cipher->encrypt_hex($plaintext);

-Paul

Replies are listed 'Best First'.
Re^2: Crypt CBC
by perlsameer (Initiate) on Jul 16, 2008 at 13:39 UTC
    Thanks, for the idea. encrypt_hex is working fine. Can you give me some more idea about blowfish and DES. As i have codes for that they are taking only 8bit string.

    please tell which encryption scheme is good for keeping a encrypted password in a webapplication
    Thanks in Advance
      Normally you wouldn't use a symmetric cipher for storing passwords (since an intruder could get the key as easily as he got a shell). Normally you use a hash to store the passwords. For example, I believe the linux shadow file uses an MD5-hmac type setup (Crypt::PasswdMD5). An attacker can still get the passwords using applications like john, but it may take a long time to get them -- if your passwords are good enough, it could take a hundred million years, but most likely it'd be more like a couple minutes.

      (Your database software probably encrypts passwords one-way with a simple password() sql function.)

      ... but if you'd really like to do it in perl, I'd suggest either Digest::MD5 or Digest::SHA1 or something in that family.

      The next question you're about to ask, I imagine, is how do you un-encrypt a hash? You don't. You do something like this to compare passwords:

      use Digest::MD5 qw(md5_hex) my %passwd = ( joe => ["I'maSalt", md5_hex("I'maSalt - secret")], ); sub login { my ($user, $pass) = @_; if( my $pa = $passwd{$user} ) { return 1 if md5_hex("$pa->[0] - $pass") eq $pa->[1]; } return 0; }

      -Paul

      The above mention solution what u have told is working but its
      giving me output 70 to 90 alphabets form just 10 character
      string.... as i want to keep this output in a text file, i
      prefer output of 7 to 10 character.. please give me solution.