搜索数据库中的加密数据 [英] Search encrypted data in Database

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

问题描述

所以我的表中有加密的记录,我想搜索这些记录。问题是,当我再次搜索并再次加密搜索词时,它会再次对其进行加密,从而生成不同的随机字符串。

So I have encrypted records in my table and I would like to search these records. The problem is that when I do search and encrypt again my search term, it encrypts it again generating different, random string.

有没有一种方法可以加密数据,以便在再次加密相同的数据时会产生与第一次加密时相同的字符串?

Is there a way to encrypt data so that when encrypting again the same data it would produce the same string as at the first time of encrypting?

示例:我正在使用CI加密库的默认设置

Example: I'm using default settings for CI encryption library

$data = "ABC";
$stored_data = $this->encryption->encrypt( $data );

$search = "ABC";
$search_data = $this->encryption->encrypt( $data );

if( $search_data == $stored_data ){
  var_dump("Found it");
}else{
  var_dump("No results");
}

上面的方法产生不同的随机字符串,因此无法搜索加密数据。是否有解决此类问题的方法?

The above produces different random strings, so there is no way of searching encrypted data. Is there a solution to this kind of problem

推荐答案

我知道这已经很晚了,但我处于类似情况。我能看到的唯一解决方案是存储数据的单独的哈希版本,然后进行查找。它确实会创建额外的数据存储空间,但是如果您仅将其存储在不应该太糟的特定字段中,那么它就可以了。您必须确保在搜索时完全匹配存储的 ,否则它将不起作用(因此,有必要降低Hash和Search值以确保准确匹配)。根据数据的安全性-选择正确的哈希值将是关键,同时良好的索引也将提高速度。在加密的字符串中添加盐也将使您的数据更安全。

I know this is late but I am in a similar situation. The only solution that I can see is store a separate hashed version of the data and then look that up. It does create extra data storage but if you only store it against specific fields that shouldn't be too bad. You must just make sure that when searching you match exactly as is stored otherwise it won't work (it may be therefore worth lowercasing your Hash and Search values to make sure). Depending on the security of the data - picking the right hash will be key as well as good indexing which would handle speed. Adding a salt to the encrypted string would also make your data more secure.

这篇关于搜索数据库中的加密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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