Xml 加密

/// <summary>
       
/// 保存用户
       
/// </summary>
        public void SetUser()
        {
            XmlDocument xmlDoc
= new XmlDocument();          // 创建一个XmlDocument 对象
            xmlDoc.Load(Application.StartupPath
+ "//user.xml");  // 加载Xml
            XmlNodeList userNodes
= xmlDoc.SelectSingleNode("root").ChildNodes; //声明XmlNodeList对象  
           
foreach (XmlNode userNode in userNodes) // 循环
            {
                XmlNodeList idandpwd
= userNode.ChildNodes; 
               
foreach (XmlNode idnode in idandpwd) // 查找密码
                {
                   
if (idnode.InnerText == cmbUserName.Text) //  用户名
                    {
                        idnode.NextSibling.InnerText
= jnzp.DESEncrypt.Encrypt(txtPwd.Text, "duowanSG");
                        xmlDoc.Save(Application.StartupPath
+ "//user.xml");
                       
return;
                    }
                }
            }

            XmlNode root
= xmlDoc.SelectSingleNode("root");//查找<root>
            XmlElement user = xmlDoc.CreateElement("user");
            XmlElement id
= xmlDoc.CreateElement("id");
            XmlElement pwd
= xmlDoc.CreateElement("pwd");
            id.InnerText
= cmbUserName.Text;
            user.AppendChild(id);
           
if (checkBox1.Checked)
            {
                pwd.InnerText
= jnzp.DESEncrypt.Encrypt(txtPwd.Text, "duowanSG");
            }
           
else
            {
                pwd.InnerText
= "";
            }
            user.AppendChild(pwd);
            root.AppendChild(user);
//添加到<bookstore>节点中
            xmlDoc.Save(Application.StartupPath + "//user.xml");

        }
       
/// <summary>
       
/// 提取密码
       
/// </summary>
       
/// <param name="userId">账号</param>
       
/// <returns></returns>
        public string GetPwd(string userId)
        {
            XmlDocument xmlDoc
= new XmlDocument();
            xmlDoc.Load(Application.StartupPath
+ "//user.xml");
            XmlNodeList userNodes
= xmlDoc.SelectSingleNode("root").ChildNodes;
           
foreach (XmlNode user in userNodes)
            {
                XmlNodeList idandpwd
= user.ChildNodes;
               
foreach (XmlNode idnode in idandpwd)
                {
                   
if (idnode.InnerText == cmbUserName.Text)
                    {
                       
string pwd=idnode.NextSibling.InnerText;
                       
if (pwd == "")
                        {
                           
return "";
                        }
                       
return jnzp.DESEncrypt.Decrypt(pwd, "duowanSG");
                    }
                }
            }
           
return "";
        }

转载于:https://www.cnblogs.com/yinbo_crazy/archive/2010/07/31/1789299.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值