SQL Server 2016 Always Encrypted 解析

本文介绍了Always Encrypted特性,包括确定性和随机性加密的区别、如何启用及应用注意事项。Always Encrypted支持两种加密模式:确定性加密允许直接在加密列上进行过滤和连接,但可能泄露模式;随机性加密更安全,但不支持索引或连接操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先最好的文档在微软的网站:

https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine?view=sql-server-2017


always encrypted 有两种方式, 一种是deterministic 和 randomized. 两者的区别:

  • Deterministic encryption always generates the same encrypted value for any given plain text value. Using deterministic encryption allows point lookups, equality joins, grouping and indexing on encrypted columns. However, but may also allow unauthorized users to guess information about encrypted values by examining patterns in the encrypted column, especially if there is a small set of possible encrypted values, such as True/False, or North/South/East/West region. Deterministic encryption must use a column collation with a binary2 sort order for character columns.

  • Randomized encryption uses a method that encrypts data in a less predictable manner. Randomized encryption is more secure, but prevents searching, grouping, indexing, and joining on encrypted columns.

如果说要在某加密列上filter 或 join 建议使用Deterministic模式



Develop using Always Encrypted with .NET Framework Data Provider

Query characteristicAlways Encrypted is enabled and application can access the keys and key metadataAlways Encrypted is enabled and application cannot access the keys or key metadataAlways Encrypted is disabled
Queries with parameters targeting encrypted columns.Parameter values are transparently encrypted.ErrorError
Queries retrieving data from encrypted columns, without parameters targeting encrypted columns.Results from encrypted columns are transparently decrypted. The application receives plaintext values of the .NET datatypes corresponding to the SQL Server types configured for the encrypted columns.ErrorResults from encrypted columns are not decrypted. The application receives encrypted values as byte arrays (byte[]).

所以对于Always Encrypted来说
有两个开关:
一个是所谓的"Always Encrypted is disabled" , 指的是是否在链接字符串里加上图中的这句话


如果开启的话, 当查询加密的字段时, 如果查询者有权限, 会自动解密, 透明传输.

另一个是Queries with parameters targeting encrypted columns.

指的是查询会不会对加密的列进行 where 这样的操作

declare @a char(10) ='str       '
select * from [dbo].[ttt] where [str] = @a

假设上面的str字段有使用always encrypted加密的话, 就必须在SSMS中开启一个选项, 见下图:


然后查询才能成功.

在dotnet编程时, 可以参考这个链接: 

https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/develop-using-always-encrypted-with-net-framework-data-provider?view=sql-server-2017

在加密列上进行操作.


补记:

在使用Azure SQL Database时, 可以用Azure Key Vault来来存储用户加密的master key(普通sqlserver使用证书)

Deterministic encryption must use a column collation with a binary2 sort order for character columns.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱知菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值