コード例 #1
0
        /// <summary>
        /// Import ListView entries from encrypted XML-Files
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="openFileDialog"></param>
        public static void ImportEncryptedFromXml(ListView listView, OpenFileDialog openFileDialog)
        {
            XDocument xDoc = XDocument.Load(openFileDialog.FileName);

            if (!File.Exists(DialogManager.GetKeyFilePath()))
            {
                return;
            }

            StreamReader reader         = new StreamReader(DialogManager.GetKeyFilePath());
            string       sEncryptionKey = reader.ReadLine();

            reader.Close();

            foreach (var item in xDoc.Descendants("pwentry"))
            {
                ListViewItem lvItem = new ListViewItem(new string[]
                {
                    Cryptography.AES_Decrypt(item.Element("title")?.Value, sEncryptionKey),
                    Cryptography.AES_Decrypt(item.Element("username")?.Value, sEncryptionKey),
                    Cryptography.AES_Decrypt(item.Element("password")?.Value, sEncryptionKey),
                    Cryptography.AES_Decrypt(item.Element("url")?.Value, sEncryptionKey),
                    Cryptography.AES_Decrypt(item.Element("notes")?.Value, sEncryptionKey)
                });
                listView.Items.Add(lvItem);
            }
        }