微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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的盲目索引优于简单散列.

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐