On Sat, 21 Sep 2002 11:31:38 -0400, [EMAIL PROTECTED] (Zentara)
wrote:

>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.
RC5 is slow on big files, especially with a high "rounds" count.

Here is an example for RC4, which is faster on bigger files than
RC5. If you want to do encryption on real big files > 5 megs, you
probably are better off selecting an module with a compiled
c component, ie. a module with .xs  Like Crypt::Rijndael.

The "pure perl modules" can be used more portably , like
from a web server, because they don't need to be compiled.

#encrypt
#################################################
#!/usr/bin/perl
use Crypt::RC4;

$passphrase = pack('C*', (0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef));

$filein = shift;

$/=undef;
open(FH,"<$filein") or die $!;
$file = (<FH>);
close FH;

$encrypted = RC4( $passphrase, $file );

open (FH,">$filein.rc4") or die $!; 
print FH $encrypted;
close FH;

exit (0);
##################################################

#decrypt
#################################################
#!/usr/bin/perl
use Crypt::RC4;

$passphrase = pack('C*', (0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef));

$filein = shift;

$/=undef;
open(FH,"<$filein") or die $!;
$file = (<FH>);
close FH;

$decrypted = RC4( $passphrase, $file );

open (FH,">$filein.decrypted") or die $!; 
print FH $decrypted;
close FH;

exit (0);
#################################################


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to