tags:

views:

52

answers:

2

Hi,

I am writing a C# class that reads a file and encrypts using Rijndael algorithm.

While testing with a 600MB file, i gets OutOfMemoryException, so planned to read the file in small chunks of 10MB each. Now the problem is that, the decryption process fails for the file whose bytes were encrypted as small chunks.

My question is, whether Rijndael encryption supports encrypting small chunks of data?

+2  A: 

Yes, it does, and you should use the CryptoStream class.

GregS
+1  A: 

Rinjadel is a block based encryption system so it only does small chunks of data anyway - 128bits at a time. You can use the output of a block as an input to the next block.

I think, maybe, the problem is in your implementation rather than the encryption method.

Posting some code would help.

Generally, your implmentation should be:

while (read 128bits from input)
{
   transform
   write 128 bits to output
}

if encrypting  
  write number of bits remaining
  read remaining data
  pad to 128 bits
  transform
  write 128 bits
else
  read number of bits left
  read 128 bits
  transform
  write number of bits left bits
Skizz
@ Marcelo Cantos: Thanks for the correcting the typo.@Skizz: Thanks for the pseudo code. As you mentioned it was a problem with the application logic. Some used streams was left unclosed which lead to OutOfMemoryException.
AJP