你好我有这个代码下面的reads Sqlconnection string
信息。但问题是我按原样存储这些信息。没有编码所以在我看来这样做是非常不安全的。有什么办法encode
,然后解码?还是散列?非常感谢您的时间和评论。
internal static class DataSource
{
private static string _ConnectionString;
public static string ConnectionString
{
get
{
if (_ConnectionString == null)
_ConnectionString = FunctionToDynamicallyCreateConnectionstring();
return _ConnectionString;
}
}
private static string FunctionToDynamicallyCreateConnectionstring()
{
string path = "C:\\Users\\marek\\Documents\\Visual Studio 2012\\Projects\\tours\\tours\\sql_string.txt";
StreamReader sr = new StreamReader(File.Open(path, FileMode.Open));
SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder();
cb.DataSource = sr.ReadLine();
cb.InitialCatalog = sr.ReadLine();
cb.UserID = sr.ReadLine();
cb.Password = sr.ReadLine();
return cb.ToString();
}
}
这就是我存储它的方式:
string path = "C:\\Users\\marek\\Documents\\Visual Studio 2012\\Projects\\tours\\tours\\sql_string.txt";
StreamWriter sw = new StreamWriter(File.Create(path));
sw.WriteLine(textBox1.Text);
sw.WriteLine(textBox2.Text);
sw.WriteLine(textBox3.Text);
sw.WriteLine(textBox4.Text);
sw.Dispose();
也许这甚至不是这样做的好方法。我是初级程序员,如果我的想法完全糟糕,请原谅。