I have some data, mostly contained in ArrayLists. I currently serialize the data, however; I would like to encrypt it.

I have created an encryption function using AES. The problem is it has to take a byte[] array and return a byte[] array.

I can encrypt the serialized file, however; some data needs to remain unencrypted. So what I need to do is encrypt the ArrayLists, serialize the file, then when i need to deserialize the file, I decrypt the ArrayLists.

What's the best way to go about doing this? I'm a bit stumpted right now.

I thought about serializing data in a memory stream, returning the byte[] and encrypting it. The problem I run into with this stragegy is, how do I store the byte[] arrays so I can serialize them with the rest of my objects and then bring it back?

I tried encrypting each System.Object inside of the ArrayLists and then putting the encrypted byte[] in. This works, however; I cannot get it back out in byte[] form. I can't deserialize because it's encrypted and casting doesn't work.

Recommendations?