加密数据的验证 [英] Validation of encrypted data

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

问题描述

我加密用户的所有隐私数据存储在数据库宝石的帮助之前,'attr_encrypted。例如,我有'EMAIL_ADDRESSES表,其中包含encrypted_email列。这种宝石解密数据,当我打电话object.email或当我通过电子邮件进行搜索。但我有问题,该列的验证。

I encrypt all private data of users before storing in database with help of gem 'attr_encrypted'. For example, I have 'email_addresses' table, which contains 'encrypted_email' column. This gem decrypt data when I call object.email or when I search by emails. But I have issues with validation of this column.

我有以下验证了这一点,其他表:

I have following validations for this and other tables:

validates_length_of :email, :within => 3..100
validates_numericality_of :post_code

我要验证解密数据之前不知怎么的,但我不知道如何与内置的Rails工具的帮助做到这一点。我不希望创造的自定义验证这一点。请指教。

I should decrypt data before validation somehow, but I don't know how to do this with help of built-in Rails tools. I don't want invent custom validations for this. Please, advise.

推荐答案

验证,这并不需要在轨道一侧的数据库查询运行,所以你可以通过一列的验证方法的方法,而不是

validations that doesn't need a db query run on the rails side so you can pass a method instead of a column to the validation methods

validates :decrypted_email, length: { within: 3..100 }

def decrypted_email
  # decrypt email here
end

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

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