php – 在MySQL中搜索加密数据的最佳方法

我在将加密数据保存到MySQL之前使用PHP进行加密.我相信,从长远来看,这是一种比使用MysqL的AES_ *功能更好的方法.

我现在的问题是,除了存储可搜索的哈希数据版本之外,是否有一种有效的方法搜索加密数据?例如,每个数据两列:first_name_encrypted,first_name_hashed.

$hashed_search = myhash('John');    
$q = "SELECT * FROM table WHERE first_name_hashed = '$hashed_search'";

这就是我现在所做的,有更好的方法吗?

解决方法:

My question Now is, is there an efficient way to search encrypted data aside from storing a searchable hashed version of the data? E.g., Two columns per data: first_name_encrypted, first_name_hashed.

关闭,但没有雪茄.见:How to search encrypted information with a blind index.

例如,使用authenticated encryption library而不是仅使用MysqL的内置AES _ *()功能

$first_name_hash = hash_hmac('sha256', $firstName, $secretKey);
$stmt = $db->prepare('SELECT * FROM table WHERE first_name_idx = ?');
$result = $db->execute([$first_name_hash])
    ->fetch(PDO::FETCH_ASSOC);
if ($result) {
    $first_name = Crypto::decrypt($result['first_name_encrypted'], $otherSecretKey);
}

基于HMAC-SHA256的盲目索引优于简单散列.

另外:使用经过身份验证的加密这是不容谈判的.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...