If you want to encrypt a file, but leave it text / xml - then you should look towards the class System.Security.Cryptography.Xml.EncryptedXml
It allows you to encrypt individual elements (using RSA or any SymmetricAlgorithm ) + can decrypt the entire file:
static void Main(string[] args) { var xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(@"C:\Temp\in.xml"); Encrypt(Create3DES("MyPasswword"), xmlDoc); xmlDoc.Save(@"C:\Temp\enc.xml"); Decrypt(Create3DES("MyPasswword"), xmlDoc); xmlDoc.Save(@"C:\Temp\dec.xml"); } private static TripleDESCryptoServiceProvider Create3DES(string password) { TripleDESCryptoServiceProvider encKey = new TripleDESCryptoServiceProvider(); MD5 md5 = new MD5CryptoServiceProvider(); encKey.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(password)); return encKey; } private static void Decrypt(SymmetricAlgorithm key, XmlDocument xmlDoc) { var encryptedXml = new EncryptedXml(xmlDoc); encryptedXml.AddKeyNameMapping("MyKey", key); encryptedXml.DecryptDocument(); } private static void Encrypt(SymmetricAlgorithm key, XmlDocument xmlDoc) { var encryptedXml = new EncryptedXml(xmlDoc); var inputElement = (XmlElement)xmlDoc.SelectSingleNode("//Data"); encryptedXml.AddKeyNameMapping("MyKey", key); var ed = encryptedXml.Encrypt(inputElement, "MyKey"); EncryptedXml.ReplaceElement(inputElement, ed, false); }