Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Basic Crypt::Blowfish usage question

by danger (Priest)
on Mar 31, 2002 at 05:54 UTC ( #155565=note: print w/replies, xml ) Need Help??

in reply to Basic Crypt::Blowfish usage question

Your problem is two-fold: First, as others have already pointed out: Blowfish is an 8-byte block encryption scheme, so you either need to pass it a string to encrypt of just 8 bytes, pad out a shorter string with nulls (\0), or work with longer data in 8-byte blocks (with padding when necessary) or get Crypt::CBC or Crypt::CBCeasy to deal with arbitrary length strings. Secondly (but your more immediate problem), your first encryption run prints out an unpacked version of the encrypted string (which is fine, makes it easier to read and type back in for the decrypt run right?) ... but in your decrypt run you try to decrypt that string as entered, you'll have to pack it up again before decrypting. Try this slight modification to your enc/dec pair:

# --- --- #!/usr/bin/perl -w use strict; use Crypt::Blowfish; my $plaintext = <>; chomp $plaintext; my $key = "this is the pass phrase"; my $cipher = Crypt::Blowfish->new($key); my $ciphertext = $cipher->encrypt($plaintext); print unpack ("H16", $ciphertext),"\n"; # --- --- #!/usr/bin/perl -w use strict; use Crypt::Blowfish; my $ciphertext = <>; chomp $ciphertext; my $key = "this is the pass phrase"; my $cipher = Crypt::Blowfish->new($key); my $plaintext = $cipher->decrypt(pack "H16",$ciphertext); print $plaintext,"\n"; # --- sample session (using 8-byte plaintext only) --- $ perl noseeums <== what I type 8db8af77b828c382 <== what I get $ perl 8db8af77b828c382 <== what I type noseeums <== what I get $ echo noseeums|perl |perl noseeums

Replies are listed 'Best First'.
Re: Re: Basic Crypt::Blowfish usage question
by DaWolf (Curate) on Mar 31, 2002 at 07:06 UTC
    Thanks a lot, danger.

    You've attacked the problem's core.

    Good aim! : )

    Er Galv„o Abbott
    a.k.a. Lobo, DaWolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://155565]
[1nickt]: Is anyone using Method::Signatures ?
[choroba]: 10 bugs in the tracker?
[1nickt]: Yes, and recommendation against using it, in the doc for Devel::Declare, on whcih it is based.
[1nickt]: I asked the new $boiss what I should brush up on before starting work next week, and he named Moo, DBIx::Class and Method::Signatures
[1nickt]: choroba That's why I asked if anyone is using it :-)
choroba only has used Moo from the htree
[1nickt]: Pardonm?

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-11-24 13:21 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (349 votes). Check out past polls.