加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 16:04:25 所属栏目:PHP教程 来源:网络整理
导读:我在将加密数据保存到 MySQL之前使用 PHP进行加密.我相信,从长远来看,这是一种比使用MySQL的AES_ *功能更好的方法. 我现在的问题是,除了存储可搜索的哈希数据版本之外,是否有一种有效的方法来搜索加密数据?例如,每个数据两列:first_name_encrypted,first_n
我在将加密数据保存到 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的盲目索引优于简单散列.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读