【问题标题】:Query encrypted data in .netcore 2在 .net core 2 中查询加密数据
【发布时间】:2019-06-14 08:37:05
【问题描述】:

我遵循了微软官方的数据加密和解密指南。我的问题是如何在数据库的数据中搜索给定的属性。例如,我想查询数据库中 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();         

【问题讨论】:

    标签: asp.net-core-webapi asp.net-core-2.2


    【解决方案1】:

    我修好了! 使用大写字母创建名字时会出现问题。所以我用于查询加密数据的更新代码是这样的:

    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();
    

    【讨论】:

      猜你喜欢
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2010-09-15
      • 2016-12-12
      相关资源
      最近更新 更多