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