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 + @"\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文件 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM