ruby-on-rails - 如何在 attr_encrypted 中搜索加密字段

标签 ruby-on-rails ruby-on-rails-4 attr-encrypted

我已经设置了attr_encrypted在我的应用程序中,每条记录都有单独的“iv”。

# Fields
User.e_name
User.e_name_iv

我正在尝试在用户表中搜索已知名称。我试过:

User.find_by_name("Joe Bloggs") # undefined method "find_by_name" for Class
User.where("name = ?", "Joe Bloggs").first # column "name" does not exist
User.where(:e_name => User.encrypt_name("Joe Bloggs"))  # must specify an iv

如何通过名称查找记录?

最佳答案

虽然可以进行一些搜索,但不是很实用。您可能必须遍历每条记录,尝试每个相应的 IV,直到获得完全匹配为止,这取决于您拥有的记录数量,这不太实用。

你读过自述文件了吗? https://github.com/attr-encrypted/attr_encrypted#things-to-consider-before-using-attr_encrypted

搜索、加入等

While choosing to encrypt at the attribute level is the most secure solution, it is not without drawbacks. Namely, you cannot search the encrypted data, and because you can't search it, you can't index it either. You also can't use joins on the encrypted data. Data that is securely encrypted is effectively noise. So any operations that rely on the data not being noise will not work. If you need to do any of the aforementioned operations, please consider using database and file system encryption along with transport encryption as it moves through your stack.

关于ruby-on-rails - 如何在 attr_encrypted 中搜索加密字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45500376/

相关文章:

html - active_link_to 列表项在非事件 CSS img 按钮时消失

mysql - attr_encrypted 和加密由 date_select 表单助手生成的日期

ruby-on-rails - 使用 attr_encrypted 生成相同密文的唯一 IV

java - 试图从 Java 解密 attr_encrypted 存储值

ruby-on-rails - 错误 : cross-thread violation on rb_gc()

ruby-on-rails - rails 3 基于多个字段查找或创建

ruby-on-rails - 如何在 Rails 中缓存模型对象?

jquery - 在每个 Turbolinks 页面中使用 jQuery 的委托(delegate)事件 on() :load

ruby-on-rails - Rails 4 中的自定义验证消息

javascript - Rails `remote: true` 未发出 AJAX 请求