AbrahamJP
AbrahamJP

Reputation: 3440

Rijndael File Chunk Encryption?

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?

Upvotes: 1

Views: 903

Answers (2)

Skizz
Skizz

Reputation: 71070

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

Upvotes: 1

President James K. Polk
President James K. Polk

Reputation: 41974

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

Upvotes: 2

Related Questions