我将连接字符串,用户名和密码存储在connectionString.config文件中。有没有办法解密所有这些值,然后像往常一样连接,如果值没有被加密?
欢迎提出所有建议,因为我不确定从何处开始,因为我没有发现Microsoft文档非常有用。
connectionString.config
<connectionStrings>
<add name="as400"
connectionString="DataSource=AgIrRzkARUJsQBUYXKCPpH8MdqtQ5Sd+lt4kyBEZBY=; userid=tRGgY7PERBTg2WPPzVerIlMP93kmQbTSuKsJKyDHFU=; password=kMxEGU75lJ1VD5OaaujnLzleR/7ZQDco3kddfwTOvI=;"/>
</connectionStrings>
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings file="AppSettings.config"/>
<connectionStrings configSource="connectionStrings.config"/>
</configuration>
应用程序代码
//Open connection to the iSeries
iDB2Connection cn = new iDB2Connection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings[database].ConnectionString;
答案 0 :(得分:1)
为了建立SQL连接,您需要先解密连接字符串,下面的代码将指导您正确的方向。
DataSet dsConnection = new DataSet();
dsConnection.ReadXml(System.Web.Hosting.HostingEnvironment.MapPath("~/ConnectionString.Config.xml"));
String connection = dsConnection.Tables[0].Rows[0]["connectionstring"].ToString();
SqlConnectionStringBuilder DBConfig = new SqlConnectionStringBuilder(connection);
string ConnectionString = "Data Source=" + Decrypt(DBConfig.DataSource) + ";Initial Catalog=" + Decrypt(DBConfig.InitialCatalog) + ";User ID=" + Decrypt(DBConfig.UserID) + ";Password=" + Decrypt(DBConfig.Password);
iDB2Connection cn = new iDB2Connection();
cn.ConnectionString = ConnectionString;
首先,您需要为AES加密创建Decrypt函数,然后您可以像上面的代码一样调用该函数。
谢谢,
Selvakumar S