生成xml

本文详细阐述了在配置管理中如何实现数据加密处理,包括密码、服务URL、调用对象、调试设置、版本号、用户名、主机名等关键信息的加密存储与解密策略。


 foreach (GridViewRow giConfig in grdConfig.Rows)
            {
                XElement XConfigElement = new XElement("Configuration");
                string configName = ((TextBox) giConfig.Cells[0].FindControl("txtConfigName")).Text;
                XConfigElement.Add(new XAttribute("Name", configName));
                string configValue = ((TextBox)giConfig.Cells[1].FindControl("txtConfigValue")).Text;
                if(configName.ToLower().Equals("password"))
                {
                    if (ViewState["password"] != null && !string.IsNullOrEmpty(ViewState["password"].ToString()))
                    {
                        string[] psdArray = ViewState["password"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("servicesurl"))
                {
                    if (ViewState["servicesUrl"] != null && !string.IsNullOrEmpty(ViewState["servicesUrl"].ToString()))
                    {
                        string[] psdArray = ViewState["servicesUrl"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("pollingobject"))
                {
                    if (ViewState["PollingObject"] != null && !string.IsNullOrEmpty(ViewState["PollingObject"].ToString()))
                    {
                        string[] psdArray = ViewState["PollingObject"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("debug"))
                {
                    if (ViewState["debug"] != null && !string.IsNullOrEmpty(ViewState["debug"].ToString()))
                    {
                        string[] psdArray = ViewState["debug"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("version"))
                {
                    if (ViewState["version"] != null && !string.IsNullOrEmpty(ViewState["version"].ToString()))
                    {
                        string[] psdArray = ViewState["version"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("username"))
                {
                    if (ViewState["username"] != null && !string.IsNullOrEmpty(ViewState["username"].ToString()))
                    {
                        string[] psdArray = ViewState["username"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                        
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }

                if (configName.ToLower().Equals("host"))
                {
                    if (ViewState["host"] != null && !string.IsNullOrEmpty(ViewState["host"].ToString()))
                    {
                        string[] psdArray = ViewState["host"].ToString().Split('#');
                        configValue = psdArray[1];
                        XConfigElement.Add(new XAttribute("Encrypted", psdArray[0]));
                    }
                    else
                        XConfigElement.Add(new XAttribute("Encrypted", "false"));
                }


                XConfigElement.Value = configValue;
                XConfig.Add(XConfigElement);
            }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值