FAQ
Hi All,

I'm trying to encrypt/decrypt a text file using Crypt::CBC with DES.

The encryption works fine but the decryption seems to yield
only the first
few bytes of the original text. I'm sure i'm missing
something simple.

Any help appreciated.

Example follows:

<enc.pl>
use strict;
use Crypt::CBC;

my $key = pack "H16", "1122334455667788";
my $cipher = new Crypt::CBC ($key, 'IDEA');

my $in;
open(IN,'e:\some_largish_text_file') || die $!;
print $cipher->encrypt($in) while read(IN,$in,1024);
print $cipher->finish;
close(IN);
</enc.pl>



<dec.pl>
use strict;
use Crypt::CBC;

if (!@ARGV) { die "Usage: perl $0 encrypted_file >
decrypted_output_file"; }

my $key = pack "H16", "1122334455667788";
my $cipher = new Crypt::CBC ($key, 'IDEA');

my $in;
open(IN,$ARGV[0]) || die $!;
print $cipher->decrypt($in) while read(IN,$in,1024);
print $cipher->finish;
close(IN);
</dec.pl>

Search Discussions

  • John W. Krahn at Oct 23, 2002 at 6:25 am

    Toby Stuart wrote:

    Hi All, Hello,
    I'm trying to encrypt/decrypt a text file using Crypt::CBC with DES.

    The encryption works fine but the decryption seems to yield
    only the first few bytes of the original text. I'm sure i'm missing
    something simple.

    perldoc -f binmode



    John
    --
    use Perl;
    program
    fulfillment
  • Toby Stuart at Oct 23, 2002 at 6:45 am
    thanks that did it.
    i always forget to binmode things :(

    cheers

    toby
    -----Original Message-----
    From: John W. Krahn
    Sent: Wednesday, October 23, 2002 4:26 PM
    To: beginners@perl.org
    Subject: Re: Crypt::CBC w/Crypt-DES


    Toby Stuart wrote:
    Hi All, Hello,
    I'm trying to encrypt/decrypt a text file using Crypt::CBC with DES.
    The encryption works fine but the decryption seems to yield
    only the first few bytes of the original text. I'm sure
    i'm missing
    something simple.

    perldoc -f binmode



    John
    --
    use Perl;
    program
    fulfillment

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedOct 23, '02 at 5:48a
activeOct 23, '02 at 6:45a
posts3
users2
websiteperl.org

2 users in discussion

Toby Stuart: 2 posts John W. Krahn: 1 post

People

Translate

site design / logo © 2021 Grokbase