perldoc Crypt::CBC covers this.
open(OUTFILE,">$destination_file") or die $!
$cipher->start('encrypting');
print OUTFILE $cipher->crypt($_) while <$UPLOADFILE>;
print OUTFILE $cipher->finish();
close(OUTFILE);
Kindest~
Dave
On 4/7/2010 7:56 AM, Fabian Gut wrote:
> Hello
>
> I have a script that reads an uploaded file, encrypts it and saves it.
> The code I use is this:
>
> # Open and read the uploaded file
> my $UPLOADFILE = $q->param('upfile');
> flock( $UPLOADFILE, 1 );
> local $/;
> my $data = <$UPLOADFILE>;
> close($UPLOADFILE);
>
> # Encrypt the file
> my $cipher = Crypt::CBC->new( -key => $key, -cipher => 'Blowfish' );
> my $enc_data = $cipher->encrypt($data);
>
> # Save the file.
> open( SAFEFILE, ">", "$file" )
> or die "FATAL ERROR: Could not create $file : $!";
> flock( SAFEFILE, 2 );
> print SAFEFILE $enc_data;
> close(SAFEFILE);
>
>
> Where $q is a CGI object, $key holds a string ("password") and $file is
> the filename for the new file.
>
> This works perfectly. However, it might become a memory issue if large
> files (several 100 MB) are uploaded. Is there a better (or easier) way
> to encrypt large files than writing the CBC myself so I can read/write
> the files block by block?
>
> Greetings
> Fabian Gut
Thread Previous