Whats the best method to encrypt a big data file?

T

thedifferenZ

Hi group,

I am trying to encrypt/decrypt a data file using asymmetic keys. I
tried using Crypt:RSA (Blowfish)

The source file is just 500kb, and its taking more than 20 mins to
encrypt it. Is there any way to encrypt a file with out taking whole
file content to memory?

========================================================
use strict;
use Crypt::RSA;
my $rsa = new Crypt::RSA;
my $public = new Crypt::RSA::Key::public(Filename => 'public.txt');
my $private = new Crypt::RSA::Key::private(Filename => 'private.txt');

open(DAT,"data.mpg");
my $message;
while(<DAT>){
$message.=$_;
}
close(DAT);
my $cyphertext = $rsa->encrypt (
Message => $message,
Key => $public,
Armour => 1,
) || die $rsa->errstr();

open(WRT,">encrypted.txt");
print WRT $cyphertext;
close(WRT);
========================================================

thanks
 
B

Brian McCauley

thedifferenZ said:
Hi group,

I am trying to encrypt/decrypt a data file using asymmetic keys. I
tried using Crypt:RSA (Blowfish)

Am I missing something? What is the connection between Crypt::RSA and
Blowfish. Blowfish AFAIK is a symetric cypher.
The source file is just 500kb, and its taking more than 20 mins to
encrypt it. Is there any way to encrypt a file with out taking whole
file content to memory?

Most symetric cypher implementations support this mode of operation.
Asymmetic algorithms are not usually used to encrypt bulk data because,
as you observe, they are slow so there's little incentive to support
this mode.

Perhaps you should use Blowfish to encrypt the bulk data with a random
key, and RSA to encrypt the key.

Or you could just use PGP that combines symetric and asymetric.
 
R

RedGrittyBrick

thedifferenZ said:
Hi group,

I am trying to encrypt/decrypt a data file using asymmetic keys. I
tried using Crypt:RSA (Blowfish)

RSA is not Blowfish.

I can't see any reference to Blowfish in your actual code nor in a quick
glance at the docs for Crypt::RSA.
The source file is just 500kb, and its taking more than 20 mins to
encrypt it.

As Brian says, Asymmetric encryption is generally slower than symmetric.

AFAIK the conventional approach is to generate a random key, use that
for a fast symmetric encryption of the plaintext, then use asymmetic
encription to encrypt the random key and include the encrypted random
key with the main ciphertext.

The recipient uses their asymmetric key to decode the random key which
can then be used to decipher the ciphertext.
Is there any way to encrypt a file with out taking whole
file content to memory?

Block mode?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top