.net core 2中查询加密数据
Query encrypted data in .netcore 2
我已经按照微软官方的数据加解密指南操作了。我的问题是如何搜索给定 属性 的数据库数据。例如,我想查询数据库中的所有数据,其中 FirstName 包含我输入的搜索名称。但是 FirstName 在数据库中是加密的,所以它有这个值:"CfDJ8GJ0pjnzz6BGph-AUfSYepqLrRxw5zqtqoh540M8wHqnnfZRuH542PMzLClloeYoQAq69kPRmUHnNdfg7J9jHc9ieIe1Vx9I_IQgt-XjUt5QE9lHknB1IKIZW6IAz_zh_w"
我可以在检索到数据后成功地保护和取消保护数据,但我无法在移动中查询数据。为了解密数据,我使用 _protector.Unprotect(),但是当我把它放在 where() 中时,它什么也不做,我也没有收到任何错误。上面的代码由于某些原因不起作用。
var customers = await _context.Customers
.Include(x => x.CustomerInformation)
.Include(x => x.CustomerContact)
.Where(x => _protector.Unprotect(x.CustomerInformation.FirstName).Contains(name))
.ToListAsync();
我修好了!
当用大写字母创建名字时会出现问题。所以我更新的查询加密数据的代码是这样的:
var customers = await _context.Customers
.Include(x => x.CustomerInformation)
.Include(x => x.CustomerContact)
Where(x =>
(_protector.Unprotect(x.CustomerInformation.FirstName).ToLower().Contains(name)) ||
(_protector.Unprotect(x.CustomerInformation.LastName).ToLower().Contains(name)) ||
(x.CustomerInformation.Code.ToLower().Contains(name))
)
.ToListAsync();
我已经按照微软官方的数据加解密指南操作了。我的问题是如何搜索给定 属性 的数据库数据。例如,我想查询数据库中的所有数据,其中 FirstName 包含我输入的搜索名称。但是 FirstName 在数据库中是加密的,所以它有这个值:"CfDJ8GJ0pjnzz6BGph-AUfSYepqLrRxw5zqtqoh540M8wHqnnfZRuH542PMzLClloeYoQAq69kPRmUHnNdfg7J9jHc9ieIe1Vx9I_IQgt-XjUt5QE9lHknB1IKIZW6IAz_zh_w"
我可以在检索到数据后成功地保护和取消保护数据,但我无法在移动中查询数据。为了解密数据,我使用 _protector.Unprotect(),但是当我把它放在 where() 中时,它什么也不做,我也没有收到任何错误。上面的代码由于某些原因不起作用。
var customers = await _context.Customers
.Include(x => x.CustomerInformation)
.Include(x => x.CustomerContact)
.Where(x => _protector.Unprotect(x.CustomerInformation.FirstName).Contains(name))
.ToListAsync();
我修好了! 当用大写字母创建名字时会出现问题。所以我更新的查询加密数据的代码是这样的:
var customers = await _context.Customers
.Include(x => x.CustomerInformation)
.Include(x => x.CustomerContact)
Where(x =>
(_protector.Unprotect(x.CustomerInformation.FirstName).ToLower().Contains(name)) ||
(_protector.Unprotect(x.CustomerInformation.LastName).ToLower().Contains(name)) ||
(x.CustomerInformation.Code.ToLower().Contains(name))
)
.ToListAsync();