您好有以下型号:
class User < ActiveRecord::Base
secret_key = ENV['DB_COL_ENCRYPTED_KEY']
attr_encrypted :email, :key => secret_key
attr_encrypted :password, :key => secret_key
[...]
end
我在模型中添加了 4 列
rails g migration AddEncryptedColumnsToUser encrypted_email:string encrypted_password:string encrypted_email_iv:string encrypted_password_iv:string
现在想检查邮箱和密码是否正确,但不知道如何处理:
secret_key_data = "my big secret 32 bits key "
email = User.encrypt_email("test@test.com", key: secret_key_data)
password = User.encrypt_password("test", key: secret_key_data)
User.where('(encrypted_email) LIKE ? AND (encrypted_password) LIKE ? ', email,password)
但是当我这样做时:
email = User.encrypt_email("test@test.com", key: secret_key_data)
我收到了这个错误:
ArgumentError: must specify an iv
问题是,我从哪里获得 iv,如果登录正确,我如何加密以便能够在数据库中进行测试?
非常感谢!