我用的是C#2005,sql server 2005
在开发的过程中用的是ado.net
自动生成了一个配置文件strconn,用文本打开可以看到用户名与密码!
请问大家有没有其它的方法,这个方法不安全!
让客户端登陆到internet sql server 的服务器上。
服务器用的是动态ip,我用的是域名绑定。简单来说就是,客户端登陆到internet sql server 的服务器上,不生成配置文件
我只会ado.net。请大家告诉我一个安全的方法。

解决方案 »

  1.   

    怎么放在类库中?
    我一新建数据集就自动生成了.cfg。
    里面的代码是xml的,看不懂!!!
    最好给我一个操作步骤。谢谢,麻烦你了。
      

  2.   

    服务器用的是动态ip,我用的是域名绑定。
    --------------------------
    这个怎么?
    用户也没有固定IP啊?怎么通信呢??
      

  3.   

    放类库里面就不说了
    就是SQL connectstring放到一个字符串变量里面存储放配置文件里就是把连接字符串写在文件中
    但是这个文件里面的用户名密码在写的时候用加密技术加密,在读的时候用解密技术解密
      

  4.   

    对strconn配置文件中的 用户名 密码 进行 des加密
    然后在程序中对其 进行解密.  #region DES_Encrypt
            /// <summary>
            /// 加密。注意:sKey输入密码的时候,必须使用英文字符,区分大小写,且字符数量是8个,不能多也不能少,否则出错。
            /// </summary>
            ///<param name="pToEncrypt">加密字符串</param>
            ///<param name="sKey">密钥</param>
            public static string DES_Encrypt(string pToEncrypt, string sKey)
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                //把字符串放到byte数组中  
                //原来使用的UTF8编码,我改成Unicode编码了,不行  
                byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
                //byte[]  inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);              //建立加密对象的密钥和偏移量  
                //原文使用ASCIIEncoding.ASCII方法的GetBytes方法  
                //使得输入密码必须输入英文文本  
                des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                //Write  the  byte  array  into  the  crypto  stream  
                //(It  will  end  up  in  the  memory  stream)  
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                //Get  the  data  back  from  the  memory  stream,  and  into  a  string  
                StringBuilder ret = new StringBuilder();
                foreach (byte b in ms.ToArray())
                {
                    //Format  as  hex  
                    ret.AppendFormat("{0:X2}", b);
                }
                return ret.ToString();
            }
            #endregion        #region DES_Decrypt
            /// <summary>
            /// 解密。
            /// </summary>
            /// <param name="pToDecrypt">解密字符串</param>
            /// <param name="sKey">密钥</param>
            public static string DES_Decrypt(string pToDecrypt, string sKey)
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();            //Put  the  input  string  into  the  byte  array  
                byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
                for (int x = 0; x < pToDecrypt.Length / 2; x++)
                {
                    int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                    inputByteArray[x] = (byte)i;
                }            //建立加密对象的密钥和偏移量,此值重要,不能修改  
                des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                //Flush  the  data  through  the  crypto  stream  into  the  memory  stream  
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();            //Get  the  decrypted  data  back  from  the  memory  stream  
                //建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象  
                StringBuilder ret = new StringBuilder();            return System.Text.Encoding.Default.GetString(ms.ToArray());
            }
            #endregion
      

  5.   

    服务器用的是adsl
    于是我用的路由动态更新ip
    路由配置中的,还在实验中。
    学网络的告诉我的,测试了好像可以通.
    我现在的问题是安全问题,forget的方法有谁会吗?
      

  6.   

    谢谢hertcloud,forget,大家吃饭去吧,呵呵,我要结帖了。谢谢大家。谢谢