コード例 #1
0
        private XmlDocument UpdateDocumentVersion(XmlDocument document, Stream stream)
        {
            string innerText = document.SelectSingleNode("/Credentials/version").InnerText;

            if (innerText != "1.0")
            {
                throw new ArgumentException(string.Format("Cannot convert document version {0} to version {1}", (object)innerText, (object)"2.0"));
            }
            XmlDocument credentialsXmlDocument = document;

            try
            {
                XmlDocument xmlDocument = (XmlDocument)credentialsXmlDocument.CloneNode(true);
                xmlDocument.SelectSingleNode("/Credentials/version").InnerText = "2.0";
                XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Credentials/passwordEntry");
                if (xmlNodeList != null)
                {
                    foreach (XmlNode xmlNode in xmlNodeList)
                    {
                        char[] password = CredentialStore.UnobfuscatePassword(xmlNode["password"].InnerText, xmlNode["host"].InnerText, xmlNode["username"].InnerText);
                        xmlNode["password"].InnerText = CredentialStore.EncryptPassword(password);
                    }
                    credentialsXmlDocument = xmlDocument;
                    CredentialStore.SaveCredentialsDocument(credentialsXmlDocument, stream);
                }
            }
            catch
            {
            }
            return(credentialsXmlDocument);
        }
コード例 #2
0
        private static void FillCredentialNode(XmlNode element, string host, string username, char[] password)
        {
            XmlElement element1 = element.OwnerDocument.CreateElement("host");

            element1.InnerText = host;
            element.AppendChild((XmlNode)element1);
            XmlElement element2 = element.OwnerDocument.CreateElement("username");

            element2.InnerText = username;
            element.AppendChild((XmlNode)element2);
            XmlElement element3 = element.OwnerDocument.CreateElement("password");

            element3.InnerText = CredentialStore.EncryptPassword(password);
            element.AppendChild((XmlNode)element3);
        }