【发布时间】:2014-06-17 09:39:26
【问题描述】:
我正在使用https://github.com/attr-encrypted/attr_encrypted 为具有以下属性的***用户模型***的活动记录加密。
激活哈希字符串 详细信息字符串 电子邮件字符串 imei 字符串 密码字符串 registration_id 字符串 安全哈希字符串我将这些属性用作
attr_encrypted_options.merge!(:prefix => 'android_', :suffix => '_sheild')
attr_encrypted :activation_hash, :key => Getter::encryption_key, :encode => true
attr_encrypted :active, :key => Getter::encryption_key, :encode => true
attr_encrypted :code, :key => Getter::encryption_key, :encode => true
attr_encrypted :details, :key => Getter::encryption_key, :encode => true
attr_encryptor :email, :key => "this is awais"
attr_encrypted :password, :key => Getter::encryption_key, :encode => true
attr_encrypted :registration_id, :key => Getter::encryption_key, :encode => true
attr_encrypted :secure_hash, :key => Getter::encryption_key, :encode => true
attr_encrypted :imei, :key => Getter::encryption_key, :encode => true
如 attr_encrypted wiki 中所述,但是当我将记录空字符串保存在存储在数据库中时。
在 Getter 中,我添加了通用加密密钥方法..
module Getter
def self.encryption_key
keys = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv
return keys
end
end
我是否需要使用我在用户模型中添加的加密属性添加迁移.. 我的目标是加密活动记录数据并将该字段保存到数据库中,当我检索时,我可以取回解密的记录,但在数据库级别这些记录不可访问。
你能告诉我我做错了什么吗?需要换宝石吗??
我们非常感谢您的建议
【问题讨论】:
-
From the doc: "默认情况下,加密的属性名称是 encrypted_#{attribute}(例如 attr_encrypted :email 会创建一个名为 encrypted_email 的属性)。因此,如果您将加密的属性存储在数据库,您需要确保表中存在 encrypted_#{attribute} 字段。”你的数据库中有这样的字段吗?
标签: ruby-on-rails ruby activerecord encryption attr-encrypted