Пример #1
0
        public static void Serialize(object obj, string FilePath, bool IsEncrypted = false)
        {
            BinaryFormatter bn  = new BinaryFormatter();
            MemoryStream    mem = new MemoryStream();

            bn.Serialize(mem, obj);
            byte[] plaindata = mem.ToArray();
            mem.Dispose();
            mem.Close();
            byte[] dataencrypted = (IsEncrypted) ? EncryptionUtility.EncryptByteArray(plaindata) :
                                   plaindata;
            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }
            FileStream file = new FileStream(FilePath, FileMode.Create);

            bn.Serialize(file, dataencrypted);
            file.Close();
        }