1

在包含密码的 .net oracle 数据库提供程序中使用连接字符串时,我遇到了一些安全问题。问题是那些提供者(System.Data.OracleClient 或 ODAC)在 String 类型的参数中获取 connectionString。

这意味着当我们有桌面应用程序直接连接到数据库(没有一些中间层服务)并且我们为此应用程序进行内存转储时,我们最有可能从传递给数据库提供程序库的 connectionString 中以纯文本形式获取用户和密码.

据我所知,没有办法在 SecureString 类型参数中传递 connectionString(谷歌说只有 MS SqlServer 提供程序允许这样做)。

在这种情况下,有没有其他方法可以保护数据库密码(除了更改系统架构和创建中间层服务以连接到数据库而不是直接从应用程序连接)?

4

1 回答 1

0

默认情况下,Microsoft 的 SqlConnection 会在.ConnectionString您连接后为您删除密码:

connection.ConnectionString = "Data Source=screwdriver;User ID=MrSnrub;Password=smithers;";
connection.Open();

>connection.ConnectionString
"Data Source=screwdriver;User ID=MrSnrub;Password=smithers;"

您可以通过指定Persist Security Info=true来覆盖此行为;:

String cs = "Data Source=screwdriver;User ID=MrSnrub;Password=smithers;Persist Security Info=true";
conn.ConnectionString = cs;
conn.Open();

>conn.ConnectionString   
"Data Source=screwdriver;User ID=MrSnrub;Password=smithers;Persist Security Info=true"

使用安全字符串

另一种方法是使用 .NET 4.5 的方法通过SqlCredential对象将密码作为SecureString传递给SqlConnection :

SecureString pwd = AzureKeyVault.GetSettingSecure("DbPassword");
SqlCredential cred = new SqlCredential("MrSnrub", pwd);

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=screwdriver;";
conn.Credential = cred;
于 2018-04-18T20:22:51.463 回答