My problem is related on how store massive informations on a 3D terrain. These informations should be secret and since they are very bulky should also be compressed. I opted for file storage and now I was wondering to know the best pracitces to encrypt/compress (or compress/encrypt) object data to files.
I just don't even know if it would be better to write to file and then compress and encrypt it or if work on a data stream and then write to file.
Any suggestion will be appreciated!
I just don't even know if it would be better to write to file and then compress and encrypt it or if work on a data stream and then write to file.
"Better" is not measurable. In-memory compression and encryption may be faster than directly writing to file, but can easily prove troublesome if the data is larger than what fits in memory.
As you do want the end result stored on disk, I'd approach it like this (first compress, then encrypt, then write to disk):
using (var compressionStream = new CompressionStream(rawData))
{
using (var encryptionStream = new EncryptionStream(compressionStream))
{
using (var fileStream = new FileStream("outputfile"))
{
encryptionStream.CopyTo(fileStream);
}
}
}
The implementations of CompressionStream
and EncryptionStream
of course depend on the APIs you use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With