我有一个Rails 7应用程序,我决定在ActivereCord模型上加密字段。我采取了以下步骤:
-
bin/rails db:加密:init
-
rails凭据:编辑 - 环境开发
,并在其中添加了密钥,
- 添加了
加密:name
立即通过执行 somemodel.where(name:'blah')
来查询模型时,即使记录在DB中,也不会返回任何记录。
但是,我可以:
- 做
somemodel.all
,并验证记录是否存在并具有我要查询的值'blah',
- 如果我更改
gencrypts:name
加密:名称,确定性:true
我做错了什么,使查询在非确定性加密字段上失败?
I have a Rails 7 app and I decided to encrypt a field on an ActiveRecord model. I took the following steps:
bin/rails db:encryption:init
rails credentials:edit --environment development
and added the keys there
- Added a
encrypts :name
to the model
Now when I query the model by doing SomeModel.where(name: 'blah')
, it doesnt return any records even though the record is in the DB.
I can however:
- Do
SomeModel.all
and verify that the record exists and has the value 'blah' that I'm querying with
- Make the query work if I change
encrypts: name
to encrypts: name, deterministic: true
What am I doing wrong that's making the queries fail on non-deterministically encrypted fields?
发布评论
评论(1)
如果要查询加密属性,则需要制作加密确定性。
因此
加密:名称,确定性:true
If you want to query the encrypted attribute, you need to make the encryption deterministic.
So
encrypts :name, deterministic: true