Самый простой подход - это, вероятно, XDocument.Load (), вокруг Linq, затем XDocument.Save (). Из приложения быстрого тестирования (не обращайте внимания на неразмещенные ресурсы):
XDocument writeContacts = new XDocument(
new XElement("contacts",
new XElement("contact",
new XElement("name", "Patrick Hines"),
new XElement("phone", "206-555-0144",
new XAttribute("type", "home")),
new XElement("phone", "425-555-0145",
new XAttribute("type", "work")),
new XElement("address",
new XElement("street1", "123 Main St"),
new XElement("city", "Mercer Island"),
new XElement("state", "WA"),
new XElement("postal", "68042")
)
)
)
);
Rijndael RijndaelAlg = Rijndael.Create();
FileStream writeStream = File.Open("data.xml", FileMode.Create);
CryptoStream cStream = new CryptoStream(writeStream,
RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV),
CryptoStreamMode.Write);
StreamWriter writer = new StreamWriter(cStream);
writeContacts.Save(writer);
writer.Flush();
writer.Close();
FileStream readStream = File.OpenRead("data.xml");
cStream = new CryptoStream(readStream,
RijndaelAlg.CreateDecryptor(RijndaelAlg.Key, RijndaelAlg.IV),
CryptoStreamMode.Read);
XmlTextReader reader = new XmlTextReader(cStream);
XDocument readContacts = XDocument.Load(reader);
//manipulate with Linq and Save() when needed
Поменяйте свой любимый ICryptoTransform в CryptoStream.