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文件