On Fri, 20 Sep 2002 08:24:30 -0400, [EMAIL PROTECTED] (Rob Das) wrote: >Hi List: > >Can anyone suggest a way/module to encrypt the contents of a file then >decrypt it to get the contents back? I see many different modules on CPAN, >but wondered if anyone can recommend one. I would be doing the encryption in >one program, and the decryption in a different program. > >Any ideas would be welcome! > The Crypt::RC4 or Crypt::RC5 are very easy. The Crypt::Rijndael (RC6) is a little harder to use because it expects a 32 byte key and a data blocksize of 16. This isn't easy even for non-newbies.
Here is an example for Crypt::RC5. Use the latest Crypt::RC5 version, there was a bug with earlier versions, if this dosn't work for you, post again and I'll post the module patch. Just run it with a filename as it's arg, and it will produce filename.rc5 and filename.rc5decypted. #encrypt ######################################################## #!/usr/bin/perl use Crypt::RC5; $key = 'e726f4a56b3e4f'; $rc5 = new Crypt::RC5($key, '12' ); $filein = shift @ARGV; open (FH,"< $filein") or die "Can't open $filein: $!"; binmode FH; while(<FH>){ $file .= $_ } close FH; $cipherfile = $rc5->encrypt($file); open(FH,"> $filein.rc5") or die "Can't open $filein.rc5: $!"; binmode FH; print FH $cipherfile; close FH; ########################################################### #decrypt ########################################################### #!/usr/bin/perl use Crypt::RC5; $key = 'e726f4a56b3e4f'; $rc5 = new Crypt::RC5($key, '12' ); $filein = shift @ARGV; open (FH,"< $filein") or die "Can't open $filein: $!"; binmode FH; while(<FH>){ $file .= $_ } close FH; $fileback = $rc5->decrypt($file); open(FH,"> $filein.decrypted") or die "Can't open $filein.rc5: $!"; binmode FH; print FH $fileback; close FH; ############################################################ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]