winform程序的appconfig加密

因为我们的C/S项目通常都要发给客户,在客户端使用。通常要和我们服务器连接。如果只是简单的app.config文件,直接是以明文方式存放数据库密码的。那么相当危险。故可以考虑加密方式。

一般采用的是:vs自带的。

 

 static void Main(string[] args)
        {
          
    string constr = @"Data Source=***。***。***。**;uid=****;pwd=****;database=****;Asynchronous Processing=true";

           


            using (SqlConnection con=new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("waitfor delay '00:00:10' select top 50 *  from TEshow", con))
                {
                    con.Open();
                    Console.WriteLine("sssssss");
                  IAsyncResult iay= cmd.BeginExecuteReader();
                  Console.WriteLine("bbbbbbb");
                  SqlDataReader dr = cmd.EndExecuteReader(iay);
                  while (dr.Read())
                  {
                      string msg = string.Format(" 第一个数是:{0},第二个数是:{1} ",dr[0].ToString(),dr[1].ToString());
                      Console.WriteLine(msg);
                  }

                  Console.ReadLine();
                }
            }
           //AddSecurity(); //加密app.config
        }

        private static string AddSecurity()
        {
            string constr = ConfigurationManager.ConnectionStrings["myCon"].ConnectionString;

            Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            conf.ConnectionStrings.SectionInformation.ProtectSection(null);
            conf.Save(ConfigurationSaveMode.Full);
            return constr;
        }

 

你可能感兴趣的:(WinForm)