asp.net读取注册表数据

using Microsoft.Win32;

 

//写入数据

 

public void Write(string key, string data)


        {
            try
            {
                data = Encrypt(data);
                RegistryKey regkey = Registry.LocalMachine.CreateSubKey(this.path);
                regkey.SetValue(key, data);
                Registry.LocalMachine.Flush();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
            }
        }

 

//读出数据

 

        public string Read(string key)
        {
            try
            {
                RegistryKey regkey = Registry.LocalMachine.OpenSubKey(this.path);
                string data = (string)regkey.GetValue(key);
                return Decrypt(data);
            }
            catch(Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                return string.Empty;
            }
        }

 

//对用户输入的信息转换

 

        private static string Encrypt(string plainText)
        {


            byte[] clearBytes = ASCIIEncoding.ASCII.GetBytes(plainText);

            PasswordDeriveBytes pdb = new PasswordDeriveBytes(ThisToken,
                new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

            byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));

            return Convert.ToBase64String(encryptedData);


        }

 

//调用写入方法

       public void WriteBug()
        {


            RegistryTools tool = new RegistryTools(@"Software/BFSL/CMMWebSite/BugReport");
            tool.Write("Path",System.Web.HttpUtility.UrlEncode( this.txt服务路径.Text));
            tool.Write("UserName", System.Web.HttpUtility.UrlEncode(this.txt用户名称.Text));
            tool.Write("ProjectName", System.Web.HttpUtility.UrlEncode(this.txt项目名称.Text));          
        }

 

// 调用读取方法

 

        private void LoadConfig()
        {

 

        private string userName;   

        private string projectName;
          RegistryTools tool = new RegistryTools(@"Software/BFSL/CMMWebSite/BugReport");
          this.url = System.Web.HttpUtility.UrlDecode(tool.Read("Path"));
          this.userName= System.Web.HttpUtility.UrlDecode(tool.Read("UserName"));
          this.projectName = System.Web.HttpUtility.UrlDecode(tool.Read("ProjectName"));


        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值