WinForm 应用程序中的安全连接字符串
如何保护 WinForm 应用程序中的 ConnectionString?
How Can I Secure my ConnectionString in WinForm Application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何保护 WinForm 应用程序中的 ConnectionString?
How Can I Secure my ConnectionString in WinForm Application?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
你不能。尽管您可以加密 app.config 文件中的连接字符串,但应用程序需要能够对其进行解密,因此始终可以检索未加密的连接字符串,尤其是对于托管应用程序(可能不适合您的典型终端)用户,但任何熟练的开发人员或黑客都可以做到这一点,甚至最终用户也可以在稍微谷歌搜索后弄清楚这一点)。
解决这个问题的方法是不要依赖模糊性安全。使用 Windows 用户帐户连接到数据库时使用Windows 集成安全性,并为用户提供数据库中的最低权限。
但这通常还不够,因为当最终用户直接连接到数据库时,很难充分保护数据库(通常是因为您需要行级安全性)。为此,您需要拒绝对表和视图的访问,并完全退回到存储过程。
然而,更好的方法是阻止桌面应用程序直接与数据库通信。相反,使用 Web 服务作为中间层。在这种情况下,您可以完全控制安全性,并且可以将连接字符串安全地存储在(Web)服务器上。
You can't. Although you can encrypt the connection string in the app.config file, the application needs to be able to decrypt it and it is, therefore, always possible to retrieve the unencrypted connection string, especially with a managed application (perhaps not for your typical end user, but any skilled developer, or hacker can do this, and even end users can figure this out after a little bit of googling).
The solution to this is to not lean on security by obscurity. Use Windows Integrated Security when connecting to the database using the Windows user account and give the user the minimum amount of rights in the database.
Often though that is still not enough, because it is very hard to secure the database enough when end users are directly connected to the database (often because you need row-level security). For this to work you need to deny access to tables and views and completely fall back to stored procedures.
A better approach, however, is to prevent the desktop application from communicating directly with the database. Instead, use a web service as intermediate layer. In that case you have full control over the security and you can store the connection string securely on the (web) server.