public object DeserializEncrypt(string FilePath)
        {
            Aes             aes          = Aes.Create();
            BinaryFormatter deserializer = new BinaryFormatter();

            try
            {
                if (File.Exists(FilePath))
                {
                    //Выполнение дессириализации из бинара:
                    using (FileStream OpenFileStream = new FileStream(FilePath + $"_{itteration++}", FileMode.Open))
                    {
                        using (CryptoStream cs = new CryptoStream(OpenFileStream, aes.CreateEncryptor(), CryptoStreamMode.Read))
                        {
                            obj = deserializer.Deserialize(OpenFileStream);
                        }
                        OpenFileStream.Close();
                    }
                    StatusDeserializEncrypt = true;
                }
                else
                {
                    Console.WriteLine("Ошибка доступа к дирректории или файлу!");
                }
            }
            catch (Exception e)
            {
                if (e == null)
                {
                    consoles.ErrorMessage(e);
                }
                StatusDeserializEncrypt = false;
            }
            return(obj);
        }
Ejemplo n.º 2
0
        public async void  SerializerToJson(object obj)
        {
            var options = new JsonSerializerOptions
            {
                WriteIndented = true
            };

            try
            {
                //Console.WriteLine( "Серриализация в JSON!" );
                using (FileStream fileStream = new FileStream(FileNameJson, FileMode.Append))
                {
                    await JsonSerializer.SerializeAsync(fileStream, obj, options);

                    ItterationJson++;
                }
            }
            catch (Exception e)
            {
                consoles.ErrorMessage(e);
            }
        }