So the basic question is in encrypting files in resource constrained devices. I have used a rather dangerous approach to use two FileStreams, where
- FileStream 1 is reading from the file and copying it to a byte array
- The contents of the byte array is encrypted.
- FileStream 2, writes the bytes back to the same file.
This works fine but has a great chance of messing up a file if the encryption stops halfway etc.
So the normal approach is to write to a temp file, and then move it to the original location and replacing the original file.
However the problem is in mobile phones where resources (especially storage) are very limited, creating lets say another 200MB or 300MB file maybe impossible.
So what approaches are there to handle this problem in Mobile Devies? Do I have to gamble between space and messing up the file?