XML文件的加密
RijndaelManaged key = new RijndaelManaged(); //设置密钥:key为32位=数字或字母16个=汉字8个 byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); key.Key = byteKey; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(Application.StartupPath + @"\FunctionEnabled.xml");//加载要加密的XML文件 if (key != null) { key.Clear(); } xmlDoc.Save(Application.StartupPath + @"\abc.xml");//生成加密后的XML文件
XML文件的解密
RijndaelManaged key = new RijndaelManaged(); //设置密钥:key为32位=数字或字母16个=汉字8个 byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); key.Key = byteKey; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(Application.StartupPath + @"\abc.xml");//加载要解密的XML文件 Encryption_and_Dcryption.Decrypt(xmlDoc, key); if (key != null) { key.Clear(); } xmlDoc.Save(Application.StartupPath + @"\FunctionEnabled.xml");//生成解密后的XML文件