日期:2014-05-19  浏览次数:20801 次

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

简单来说就是,客户端登陆到internet   sql   server   的服务器上,不生成配置文件
我只会ado.net。请大家告诉我一个安全的方法。


------解决方案--------------------
1.你可以不在配置文件裡寫用戶名和密碼,直接放在類庫或者程序文件中;
2.你可以使用配置文件,但配置文件中的用戶名和密碼是加密存儲的,在程序中動態解密。
------解决方案--------------------
放类库里面就不说了
就是SQL connectstring放到一个字符串变量里面存储

放配置文件里就是把连接字符串写在文件中
但是这个文件里面的用户名密码在写的时候用加密技术加密,在读的时候用解密技术解密
------解决方案--------------------
对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(), CryptoStreamMod