internal string DecryptSection (string encryptedXml, ProtectedConfigurationProvider protectionProvider) { XmlDocument doc = new ConfigurationXmlDocument (); doc.InnerXml = encryptedXml; XmlNode decryptedNode = protectionProvider.Decrypt (doc.DocumentElement); return decryptedNode.OuterXml; }
internal string EncryptSection (string clearXml, ProtectedConfigurationProvider protectionProvider) { XmlDocument doc = new ConfigurationXmlDocument (); doc.LoadXml (clearXml); XmlNode encryptedNode = protectionProvider.Encrypt (doc.DocumentElement); return encryptedNode.OuterXml; }
internal string DecryptSection(string encryptedXml, ProtectedConfigurationProvider protectionProvider) { XmlDocument doc = new ConfigurationXmlDocument(); doc.InnerXml = encryptedXml; XmlNode decryptedNode = protectionProvider.Decrypt(doc.DocumentElement); return(decryptedNode.OuterXml); }
internal string EncryptSection(string clearXml, ProtectedConfigurationProvider protectionProvider) { XmlDocument doc = new ConfigurationXmlDocument(); doc.LoadXml(clearXml); XmlNode encryptedNode = protectionProvider.Encrypt(doc.DocumentElement); return(encryptedNode.OuterXml); }
void DoDeserializeSection(XmlReader reader) { reader.MoveToContent(); string protection_provider = null; string config_source = null; string localName; while (reader.MoveToNextAttribute()) { localName = reader.LocalName; if (localName == "configProtectionProvider") { protection_provider = reader.Value; } else if (localName == "configSource") { config_source = reader.Value; } } /* XXX this stuff shouldn't be here */ { if (protection_provider != null) { ProtectedConfigurationProvider prov = ProtectedConfiguration.GetProvider(protection_provider, true); XmlDocument doc = new ConfigurationXmlDocument(); reader.MoveToElement(); doc.Load(new StringReader(reader.ReadInnerXml())); XmlNode n = prov.Decrypt(doc); reader = new XmlNodeReader(n); SectionInformation.ProtectSection(protection_provider); reader.MoveToContent(); } } if (config_source != null) { SectionInformation.ConfigSource = config_source; } SectionInformation.SetRawXml(RawXml); if (SectionHandler == null) { DeserializeElement(reader, false); } }
protected internal virtual object GetRuntimeObject() { if (SectionHandler != null) { ConfigurationSection parentSection = sectionInformation != null?sectionInformation.GetParentSection() : null; object parent = parentSection != null?parentSection.GetRuntimeObject() : null; if (RawXml == null) { return(parent); } try { // This code requires some re-thinking... XmlReader reader = new ConfigXmlTextReader( new StringReader(RawXml), Configuration.FilePath); DoDeserializeSection(reader); if (!String.IsNullOrEmpty(SectionInformation.ConfigSource)) { string fileDir = SectionInformation.ConfigFilePath; if (!String.IsNullOrEmpty(fileDir)) { fileDir = Path.GetDirectoryName(fileDir); } else { fileDir = String.Empty; } string path = Path.Combine(fileDir, SectionInformation.ConfigSource); if (File.Exists(path)) { RawXml = File.ReadAllText(path); SectionInformation.SetRawXml(RawXml); } } } catch { // ignore, it can fail - we deserialize only in order to get // the configSource attribute } XmlDocument doc = new ConfigurationXmlDocument(); doc.LoadXml(RawXml); return(SectionHandler.Create(parent, ConfigContext, doc.DocumentElement)); } return(this); }
public override XmlNode Encrypt (XmlNode node) { XmlDocument doc = new ConfigurationXmlDocument (); doc.Load (new StringReader (node.OuterXml)); EncryptedXml ex = new EncryptedXml (doc); ex.AddKeyNameMapping ("Rsa Key", GetProvider ()); EncryptedData d = ex.Encrypt (doc.DocumentElement, "Rsa Key"); return d.GetXml(); }
public override XmlNode Decrypt (XmlNode encrypted_node) { XmlDocument doc = new ConfigurationXmlDocument (); doc.Load (new StringReader (encrypted_node.OuterXml)); EncryptedXml ex = new EncryptedXml (doc); ex.AddKeyNameMapping ("Rsa Key", GetProvider ()); ex.DecryptDocument (); return doc.DocumentElement; }
public override XmlNode Encrypt(XmlNode node) { XmlDocument doc = new ConfigurationXmlDocument(); doc.Load(new StringReader(node.OuterXml)); EncryptedXml ex = new EncryptedXml(doc); ex.AddKeyNameMapping("Rsa Key", GetProvider()); EncryptedData d = ex.Encrypt(doc.DocumentElement, "Rsa Key"); return(d.GetXml()); }
public override XmlNode Decrypt(XmlNode encrypted_node) { XmlDocument doc = new ConfigurationXmlDocument(); doc.Load(new StringReader(encrypted_node.OuterXml)); EncryptedXml ex = new EncryptedXml(doc); ex.AddKeyNameMapping("Rsa Key", GetProvider()); ex.DecryptDocument(); return(doc.DocumentElement); }
public virtual object GetRuntimeObject () { if (SectionHandler != null) { ConfigurationSection parentSection = sectionInformation != null ? sectionInformation.GetParentSection () : null; object parent = parentSection != null ? parentSection.GetRuntimeObject () : null; if (RawXml == null) return parent; try { // This code requires some re-thinking... XmlReader reader = new ConfigXmlTextReader ( new StringReader (RawXml), Configuration.FilePath); DoDeserializeSection (reader); if (!String.IsNullOrEmpty (SectionInformation.ConfigSource)) { string fileDir = SectionInformation.ConfigFilePath; if (!String.IsNullOrEmpty (fileDir)) fileDir = Path.GetDirectoryName (fileDir); else fileDir = String.Empty; string path = Path.Combine (fileDir, SectionInformation.ConfigSource); if (File.Exists (path)) { RawXml = File.ReadAllText (path); SectionInformation.SetRawXml (RawXml); } } } catch { // ignore, it can fail - we deserialize only in order to get // the configSource attribute } XmlDocument doc = new ConfigurationXmlDocument (); doc.LoadXml (RawXml); return SectionHandler.Create (parent, ConfigContext, doc.DocumentElement); } return this; }
void DoDeserializeSection (XmlReader reader) { reader.MoveToContent (); string protection_provider = null; string config_source = null; string localName; while (reader.MoveToNextAttribute ()) { localName = reader.LocalName; if (localName == "configProtectionProvider") protection_provider = reader.Value; else if (localName == "configSource") config_source = reader.Value; } /* XXX this stuff shouldn't be here */ { if (protection_provider != null) { ProtectedConfigurationProvider prov = ProtectedConfiguration.GetProvider (protection_provider, true); XmlDocument doc = new ConfigurationXmlDocument (); reader.MoveToElement (); doc.Load (new StringReader (reader.ReadInnerXml ())); XmlNode n = prov.Decrypt (doc); reader = new XmlNodeReader (n); SectionInformation.ProtectSection (protection_provider); reader.MoveToContent (); } } if (config_source != null) SectionInformation.ConfigSource = config_source; SectionInformation.SetRawXml (RawXml); if (SectionHandler == null) DeserializeElement (reader, false); }