保护 C# 应用程序中的数据层 [英] Securing your Data Layer in a C# Application

查看:20
本文介绍了保护 C# 应用程序中的数据层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在考虑如何保护 C# 应用程序中的数据层,在这种情况下,该层可以是一个 LINQ to SQL 模型图,与应用程序本身一起存储,其中包含到 SQL Server 数据库的连接字符串.

I was thinking about how to secure the Data Layer in a C# Application, the layer could in this case be either a LINQ to SQL Model Diagram stored with the Application itself containg the connection string to the SQL Server Database.

或者可能是应用程序和网络服务之间的连接.

Or it could be connectivity between the application and webservices.

或者您需要实现某种安全性,例如,应用程序中的连接字符串很容易被逆向工程,并且 Web 服务可以很容易地被跟踪和用于应用程序原始目的以外的其他原因.

Either you need to impement some sort of security, for instance, the Connection String in a Application can easily be reverse engineered and Webservices can easily be tracked and used for other reasons than the applications original purpose.

所以我的问题是简短的:在处理 Web 服务和/或从 Windows 窗体应用程序直接连接到 SQL Server 时,您如何解决安全问题?

So my question is in a shorter way: How do you solve the security issues when handling Webservices and/or direct connection to a SQL Server From a Windows Forms Application?

推荐答案

在你的情况下,有两种主要的攻击可能性:

In your case there are two main attack possibilities:

  • 窃取连接字符串,然后直接访问数据库
  • 在不使用 UI 的情况下直接调用 C# 代码中的方法

对于连接字符串,您需要将其以加密形式存储在配置文件中.问题是winforms应用程序中需要有足够的信息才能解密和使用它.

For the connection string you need to store it in an encrypted form in a config file. Problem is that there need to be enough information in the winforms app so that it can decrypt and use it.

为了直接访问代码,您可以使用代码访问安全和混淆.

For accessing the code directly you can use code access security and obfuscation.

在您的情况下,我不会让 Windows 应用程序直接访问数据库.让windows app调用WCF服务,WCF服务会访问数据库.

In your case I would not give the windows app direct access to the database. Let the windows app call a WCF service, the the WCF service would access the database.

用户的用户账号被允许调用WCF服务,WCF服务运行在一个允许访问数据库的账号下,用户的用户账号对数据库没有权限.

The user's user account is allowed to call the WCF service, the WCF service is running under an account that is allowed to access the database, the user's user account has no rights to the database.

具有 3 层的 Windows 应用程序:

Windows App with 3 Layers:

  • 界面
  • 业务(安全检查应向用户显示什么 UI)
  • 代理

2 层的 WCF 服务:

WCF Service with 2 Layers:

  • 外观/业务层(安全检查允许用户使用此数据调用此方法)
  • 实体框架数据模型

两个层的通用dll

  • 合同/WCF 接口
  • 数据传输对象

有关代理、合同和 DTO 的信息,请观看此视频:

For info on proxy, contracts and DTO's see this video:

http://www.dnrtv.com/default.aspx?showNum=103

这篇关于保护 C# 应用程序中的数据层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆