Laravel-LIKE运算符来搜索加密值 [英] Laravel - LIKE operator to search for encrypted values

查看:45
本文介绍了Laravel-LIKE运算符来搜索加密值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Laravel应用中实现一个搜索模块,该模块可以按名称过滤用户.为了保护用户,'name'列行在DB上进行了加密.我面临的问题是,下面的查询始终返回0个结果.

I am trying to implement a search module in my Laravel app that could filter users by name. In order to protect users, the 'name' column rows are encrypted on DB. The problem that I am facing is that query below always returns 0 results.

在搜索数据库之前,我正在加密搜索输入值.

I am encrypting the search input value before searching into DB.

$patients = DB::select( DB::raw("SELECT * FROM patient WHERE name LIKE '%".Crypt::encrypt($searchText)."%';"));

我在这里做什么错了?

推荐答案

我在这里做什么错了?

What am I doing wrong here ?

Laravel的加密已正确实施,这意味着每封邮件都是随机

Laravel's encryption is properly implemented, which means that each message is randomized!

随机化带来了实现可搜索加密的挑战:永远不会两次获得相同的密文.幸运的是,有一个进行加密的解决方法可搜索的.

Randomization introduces a challenge for implementing searchable encryption: You never get the same ciphertext twice. Fortunately, there's a workaround for making encryption searchable.

  1. 使用经过身份验证的加密对每条记录进行加密.
  2. 分别存储纯文本格式的HMAC-SHA2/BLAKE2(使用与加密密钥不同的密钥).您可以截断哈希函数输出.这称为盲目索引.
    • 此外,您可以存储各种切片或明文转换的多个哈希函数.(例如,后4位数字,名字的首字母+姓氏等)
    • 每个盲索引都应有一个不同的键.
    • 您可以将多个字段组合成一个盲指标.
    • 对于低熵输入(例如,布尔字段),这听起来可能很多,但实际上, CipherSweet 实现了所有低级机制并且对于大多数PHP开发人员来说应该足够容易使用.(如果事实并非如此,请在Github上提交错误;我们希望如此!)

      This may sound like a lot, but in practice, CipherSweet implements all the low-level machinery and should be easy enough for most PHP developers to use. (If this turns out to not be the case, file a bug on Github; we want it to be the case!)

      这篇关于Laravel-LIKE运算符来搜索加密值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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