Exemplo n.º 1
0
        private bool SaveToFile(TData data)
        {
            try
            {
                var json = JsonConvert.SerializeObject(data);
                var aes  = EncryptionProvider.EncryptText(json, _StorageSalt);
                var md5  = EncryptionProvider.MD5($"{aes}_{_StorageSalt}");

                var j = new SedeRootDto
                {
                    EncryptedData = aes,
                    Md5           = md5
                };

                var rj = JsonConvert.SerializeObject(j);

                using (var f = new FileStream(_jsonFilePath,
                                              FileMode.Create,
                                              FileAccess.Write,
                                              FileShare.ReadWrite))
                {
                    using (var r = new StreamWriter(f, Encoding.UTF8))
                    {
                        r.Write(rj);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                //add logger here
                throw;
            }
        }