public LocalStorageManager(string password)
        {
            this.password = password;

            if (File.Exists(this.StoragePath))
            {
                this.diskStorage = StorageProvider.Load(this.StoragePath, password);
            }
            else
            {
                this.diskStorage = new DiskStorage();
            }
        }
Example #2
0
        public void Save(DiskStorage diskStorage, string storagePath, string password)
        {
            var json     = JsonConvert.SerializeObject(diskStorage, Formatting.Indented);
            var jsonData = Encoding.UTF8.GetBytes(json);

            using (var input = new MemoryStream(jsonData))
                using (var output = File.Create(storagePath))
                {
                    if (password == null)
                    {
                        input.CopyTo(output);
                    }
                    else
                    {
                        SymmetricEncryption.Encrypt(input, output, password);
                    }
                }
        }