我在将加密数据保存到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的盲目索引优于简单散列.
另外:使用经过身份验证的加密这是不容谈判的.