简体   繁体   English

加密SQL Server 2008中某些字段的最佳方法?

[英]Best way to encrypt certain fields in SQL Server 2008?

I'm writing a .NET web app that will read and write information to a SQL Server 2008 database. 我正在编写一个.NET Web应用程序,它将读取和写入信息到SQL Server 2008数据库。 Some of this information will be highly confidential in nature so I want to encrypt certain data elements. 其中的某些信息本质上将是高度机密的,因此我想对某些数据元素进行加密。

I don't want to use TDE or any full-database encryption for performance reasons. 由于性能原因,我不想使用TDE或任何全数据库加密。 My main concern is protecting this sensitive data as a last resort against a SQL injection or even a database server compromise. 我主要关心的是保护这些敏感数据,以防SQL注入甚至数据库服务器受损。

What is the best way to do this to preserve performance? 这样做以保持性能的最佳方法是什么? Is it faster to use the SQL Server 2008 encryption functions such as EncryptByKey , or would it be faster to encrypt and decrypt the data in the .NET web app itself? 使用SQL Server 2008加密函数(例如EncryptByKey )是否更快,或者对.NET Web应用程序本身中的数据进行加密和解密会更快? The app would be using a symmetric key stored in the secure web.config and store the encrypted values in the DB. 该应用程序将使用存储在安全web.config中的对称密钥,并将加密后的值存储在DB中。

I've always followed the rule that if what you are trying to do is data related with no business rules then it should be done in the database, that way you don't have to worry about it again... for example if you were to write another application, you'd already have the encryption setup and not have to write any extra code. 我一直遵循以下规则:如果您要执行的操作是与无业务规则相关的数据,则应在数据库中完成,这样就不必再担心它了……例如,如果您如果要编写另一个应用程序,您已经具有加密设置,而不必编写任何其他代码。 This include not needing to test again or introduce any new bugs. 这包括不需要再次测试或引入任何新的错误。

我已经使用第三方库在Web应用程序内部进行了数据加密,但我确实认为,与SQL2008 EncryptByKey中的数据加密方法相比,它会更慢。

I have not used the database encryption, but my recommendation would do the encryption in the application level. 我没有使用数据库加密,但是我的建议是在应用程序级别进行加密。 Down the line if for whatever reasons your database needs change, the encryption logic will be in the application layer and not the database layer. 如果由于某种原因需要更改数据库,则加密逻辑将在应用程序层而不是数据库层中进行。

I am not exactly sure of the speeds between the two, but the maintenance of the project will be easier down the line if it is maintained in the application layer. 我不确定这两者之间的速度,但是如果将项目维护在应用程序层中,则可以更轻松地进行项目维护。 As for encryption, this website is a good read for designing your encryption and decryption logic and salting. 至于加密,此网站是设计加密和解密逻辑以及添加盐分的很好的阅读材料。

Encrypt and Decrypt Data Using a Symmetric (Rijndael) Key 使用对称(Rijndael)密钥加密和解密数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM