コード例 #1
0
        private void Decrypt_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckInputFields())
            {
                return;
            }
            if (!File.Exists(FileLocation))
            {
                return;
            }

            var encryptedBytes  = File.ReadAllBytes(FileLocation);
            var decryptedBytes  = _encrypter.Decrypt(encryptedBytes, Password);
            var memoryStream    = new MemoryStream();
            var binaryFormatter = new BinaryFormatter();

            memoryStream.Write(decryptedBytes, 0, decryptedBytes.Length);
            memoryStream.Position = 0;
            try
            {
                var deserialised = (SortedObservableCollection <Entry>)binaryFormatter.Deserialize(memoryStream);
                Entries.Clear();
                Entries.AddAll(deserialised);
                FileOpen = true;
            }
            catch (Exception ex) when(ex is DecoderFallbackException || ex is SerializationException)
            {
            }
        }