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);
        }
        public void ClearPasswords()
        {
            if (this._objectAlreadyDisposed)
            {
                throw new ObjectDisposedException("CredentialStore");
            }
            if (!File.Exists(this._credentialFilePath))
            {
                return;
            }
            FileStream fileStream = (FileStream)null;

            try
            {
                fileStream = this.OpenFile(FileShare.None);
                XmlDocument credentialsXmlDocument = this.LoadCredentialsDocument((Stream)fileStream);
                XmlNode     xmlNode = credentialsXmlDocument.SelectSingleNode("/Credentials");
                foreach (XmlNode oldChild in credentialsXmlDocument.SelectNodes("/Credentials/passwordEntry"))
                {
                    xmlNode.RemoveChild(oldChild);
                }
                CredentialStore.SaveCredentialsDocument(credentialsXmlDocument, (Stream)fileStream);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }
        }
        public bool RemovePassword(string host, string username)
        {
            if (this._objectAlreadyDisposed)
            {
                throw new ObjectDisposedException("CredentialStore");
            }
            bool flag = false;

            if (File.Exists(this._credentialFilePath))
            {
                FileStream fileStream = (FileStream)null;
                try
                {
                    fileStream = this.OpenFile(FileShare.None);
                    XmlDocument credentialsXmlDocument = this.LoadCredentialsDocument((Stream)fileStream);
                    XmlNode     credentialNode         = CredentialStore.GetCredentialNode(credentialsXmlDocument, host, username, this._isUsernameCaseSensitive);
                    flag = credentialNode != null;
                    if (credentialNode != null)
                    {
                        credentialsXmlDocument.SelectSingleNode("/Credentials").RemoveChild(credentialNode);
                        CredentialStore.SaveCredentialsDocument(credentialsXmlDocument, (Stream)fileStream);
                    }
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Dispose();
                    }
                }
            }
            return(flag);
        }
        public bool AddPassword(string host, string username, char[] password)
        {
            if (this._objectAlreadyDisposed)
            {
                throw new ObjectDisposedException("CredentialStore");
            }
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentException("Host name cannot be empty.", "host");
            }
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentException("User name cannot be empty.", "username");
            }
            if (password == null)
            {
                password = new char[0];
            }
            FileStream fileStream = (FileStream)null;
            bool       flag;

            try
            {
                if (!File.Exists(this._credentialFilePath))
                {
                    using (File.Create(this._credentialFilePath, 8192, FileOptions.RandomAccess, CredentialStore.GetSecuritySettings()))
                        ;
                    fileStream = this.OpenFile(FileShare.None);
                    CredentialStore.InitializeCredentialsDocument((Stream)fileStream);
                }
                else
                {
                    fileStream = this.OpenFile(FileShare.None);
                }
                XmlDocument credentialsXmlDocument = this.LoadCredentialsDocument((Stream)fileStream);
                XmlNode     xmlNode = CredentialStore.GetCredentialNode(credentialsXmlDocument, host, username, this._isUsernameCaseSensitive);
                flag = xmlNode == null;
                if (xmlNode == null)
                {
                    xmlNode = (XmlNode)credentialsXmlDocument.CreateElement("passwordEntry");
                }
                else
                {
                    xmlNode.RemoveAll();
                }
                CredentialStore.FillCredentialNode(xmlNode, host, username, password);
                Array.Clear((Array)password, 0, password.Length);
                credentialsXmlDocument.SelectSingleNode("/Credentials").AppendChild(xmlNode);
                CredentialStore.SaveCredentialsDocument(credentialsXmlDocument, (Stream)fileStream);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }
            return(flag);
        }
        private static void InitializeCredentialsDocument(Stream credentialsFile)
        {
            XmlDocument credentialsXmlDocument = new XmlDocument();

            credentialsXmlDocument.AppendChild((XmlNode)credentialsXmlDocument.CreateXmlDeclaration("1.0", "UTF-8", (string)null));
            XmlElement element1 = credentialsXmlDocument.CreateElement("Credentials");
            XmlElement element2 = credentialsXmlDocument.CreateElement("version");

            element2.InnerText = "2.0";
            element1.AppendChild((XmlNode)element2);
            credentialsXmlDocument.AppendChild((XmlNode)element1);
            CredentialStore.SaveCredentialsDocument(credentialsXmlDocument, credentialsFile);
        }