No, it’s not, but ...
I just added GZipStream support for my application today, so I can share some code here;
Serialization:
using (Stream s = File.Create(PathName)) { RijndaelManaged rm = new RijndaelManaged(); rm.Key = CryptoKey; rm.IV = CryptoIV; using (CryptoStream cs = new CryptoStream(s, rm.CreateEncryptor(), CryptoStreamMode.Write)) { using (GZipStream gs = new GZipStream(cs, CompressionMode.Compress)) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(gs, _instance); } } }
Deserialization:
using (Stream s = File.OpenRead(PathName)) { RijndaelManaged rm = new RijndaelManaged(); rm.Key = CryptoKey; rm.IV = CryptoIV; using (CryptoStream cs = new CryptoStream(s, rm.CreateDecryptor(), CryptoStreamMode.Read)) { using (GZipStream gs = new GZipStream(cs, CompressionMode.Decompress)) { BinaryFormatter bf = new BinaryFormatter(); _instance = (Storage)bf.Deserialize(gs); } } }
NOTE. If you use CryptoStream, it is important that you chain (un) zipping and (de) encrypt this way because you want to lose your entropy BEFORE encryption creates noise from your data.
Daniel Mošmondor
source share