Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crypt Module?

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
All,

I need to encrypt a file while it is not in use and I am wondering which of the crypt modules out there for PERL is the best. I would prefer not to use the unix implementation of crypt, but I do need it to have the same functionality.

Thanks in advance.
 
AFAIK, crypt is a standard function in Perl. I've used Crypt::Blowfish in the past, and found it pretty good

You can get that from
HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
The standard crypt function is not good for file encryption since it is a one-way encryption.

Paul's suggestion is a good one. You can use the various Crypt:: modules from CPAN (I like Crypt::Blowfish or Crypt::Loki97).

Since you are talking about encrypting a file you will want to use Crypt::CBC or some other type of 'cipher block chaining' module. Most encryption routines can only handle a small ammount of data so CBC's allow you to string larger chunks together without having worry about looping and padding the ciphers.

Hope that helps.
 
Thanks for the replies and the advice. After looking into this I have gone with the following implemenation:

Crypt::CBC using 'Blowfish'

I have two small scripts based on the Crypt::CBC module page from cpan.org, but I am unable to get them to work correctly. The test file encrypts, but then when I go to decrypt the encrypted file, it does not decrypt.

==============================================================
enc.pl

#!/usr/bin/perl -w

use Crypt::CBC;
use FileHandle;
use strict;
open(CT,">ct.dat");
open(PT,"<pt.txt");

my $cipher = new Crypt::CBC({'key' => 't1234',
'cipher' => 'Blowfish',
'padding' => 'space'});
undef $/;
print CT $cipher->encrypt(<PT>);

close(CT);
close(PT);
exit(0)
# EOS
============================================================
============================================================
dec.pl

#!/usr/bin/perl -w

use Crypt::CBC;
use FileHandle;
use strict;
open(CT,"<ct.dat");
open(PT,">pt.dat");

my $cipher = new Crypt::CBC({'key' => 't1234',
'cipher' => 'Blowfish',
'padding' => 'space'});
undef $/;
print PT $cipher->decrypt(<CT>);

close(CT);
close(PT);
exit(0)
# EOS
============================================================

Any thoughts as to what I am doing wrong? I shouldn't have to use the $cipher->start('encrypting'); and $cipher->finished(); methods since the $cipher->(encrypt or decrypt)(<TEXT>); method is supposed to take care of this.

Thanks in advance.
 
Nevermind, looks like my LANG variable was set incorrectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top