示例#1
0
        /// <summary>
        /// Export ListView entries into encrypted XML-Files for saveDialog
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="saveFileDialog"></param>
        public static void ExportEncryptedToXml(ListView listView, SaveFileDialog saveFileDialog)
        {
            string sEncryptionKey = null;

            XmlWriterSettings xmlSettings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true,
                CloseOutput         = true
            };

            if (File.Exists(DialogManager.GetKeyFilePath()))
            {
                StreamReader reader = new StreamReader(DialogManager.GetKeyFilePath());
                sEncryptionKey = reader.ReadLine();
                reader.Close();
            }
            if (File.Exists(DialogManager.GetKeyFilePathSave()))
            {
                StreamReader reader = new StreamReader(DialogManager.GetKeyFilePathSave());
                sEncryptionKey = reader.ReadLine();
                reader.Close();
            }
            XmlWriter xmlWriter = XmlWriter.Create(saveFileDialog.FileName, xmlSettings);

            xmlWriter.WriteStartElement("pwlist");

            for (int index = 0; index < listView.Items.Count; index++)
            {
                xmlWriter.WriteStartElement("pwentry");

                xmlWriter.WriteStartElement("title");
                xmlWriter.WriteString(Cryptography.AES_Encrypt(listView.Items[index].SubItems[0].Text, sEncryptionKey));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("username");
                xmlWriter.WriteString(Cryptography.AES_Encrypt(listView.Items[index].SubItems[1].Text, sEncryptionKey));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("password");
                xmlWriter.WriteString(Cryptography.AES_Encrypt(listView.Items[index].SubItems[2].Text, sEncryptionKey));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("url");
                xmlWriter.WriteString(Cryptography.AES_Encrypt(listView.Items[index].SubItems[3].Text, sEncryptionKey));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("notes");
                xmlWriter.WriteString(Cryptography.AES_Encrypt(listView.Items[index].SubItems[4].Text, sEncryptionKey));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
            xmlWriter.Close();
        }
示例#2
0
        /// <summary>
        /// Save MainWindow settings XML-File
        /// </summary>
        /// <param name="Window"></param>
        /// <param name="sFilename"></param>
        public static void SaveConfigXml(Form Window, string sFilename)
        {
            XmlWriterSettings xmlSettings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true
            };

            XmlWriter xmlWriter = XmlWriter.Create(sFilename, xmlSettings);

            xmlWriter.WriteStartElement("mainWindow");

            xmlWriter.WriteStartElement("settings");

            xmlWriter.WriteStartElement("width");
            xmlWriter.WriteString(Window.Width.ToString());
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("height");
            xmlWriter.WriteString(Window.Height.ToString());
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("left");
            xmlWriter.WriteString(Window.Location.X.ToString());
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("top");
            xmlWriter.WriteString(Window.Location.Y.ToString());
            xmlWriter.WriteEndElement();

            if (File.Exists(DialogManager.GetKeyFilePath()))
            {
                xmlWriter.WriteStartElement("recentKeyPath");
                xmlWriter.WriteString(DialogManager.GetKeyFilePath());
                xmlWriter.WriteEndElement();
            }
            if (File.Exists(DialogManager.GetKeyFilePathSave()))
            {
                xmlWriter.WriteStartElement("recentKeyPath");
                xmlWriter.WriteString(DialogManager.GetKeyFilePathSave());
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
            xmlWriter.Close();
        }