您的位置:首页 > 其它

XML文件的加密与解密

2013-04-22 21:23 1356 查看
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文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: