Maybe something along these lines? Your question is pretty generic...
const int SEGMENT_SIZE = 4096;
int segment, i;
f(byte[] data, int offset, int length)
{
byte[] output = new byte[length];
// TODO: implement
return output;
}
segment = 0;
while(segment * SEGMENT_SIZE < buffer.Length)
{
output = f(buffer, segment * SEGMENT_SIZE, SEGMENT_SIZE);
segment++;
}
Output without segments:
g(byte[] src, byte[] dst, int srcOffset, int dstOffset, int length)
{
// TODO: implement process from src[srcOffset + i] to dst[dstOffset + i]
// no return, has side-effect on dst
}
outputBuffer = new byte[inputBuffer.Length];
segment = 0;
while(segment * SEGMENT_SIZE < inputBuffer.Length)
{
g(inputBuffer, outputBuffer, segment * SEGMENT_SIZE, segment * SEGMENT_SIZE, SEGMENT_SIZE);
segment++;
}
AES encryption maintains the size of the blocks, so data will be aligned block-by-block. Pay attention to padding, last segment might be partial. Use the right padding, I've had a hard time to get it working because of a bad padding. Also make sure you can have 4096 byte blocks... IIRC you should use 2 blocks of 256 bytes each. Either way, you'll have to fiddle with values quite a lot! Good luck :)