Encrypting parts of a Serialized File
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?
Re: Encrypting parts of a Serialized File
I can't give you a completely clear answer on this, but in general terms I'd think that you would create a class that implements ISerializable and then code the encryption into the serialisation right there in the class. You could create the encrytped byte array and convert that to a string before saving to the file. When you deserialise you would convert the string to a byte array and decrypt.
Re: Encrypting parts of a Serialized File
How would you originally get it into a byte[] array before the serialization?