attr_encrypted
生成透明加密和解密属性的attr_accessors。
但是,在使用 ActiveRecord。DataMapper 或者 Sequel 时,你可以获得一些额外的特性。
安装
将attr_encrypted添加到你的gemfile:
gem attr_encrypted, ~ 3.0.0
然后安装 gem:
bundle install
用法
如果使用的是 ActiveRecord,DataMapper 或者 Sequel 这样的ORM,使用attr_encrypted很容易:
class User
attr_encrypted :ssn, key: This is a key that is 256 bits!!
end
如果使用 PORO,则需要通过扩展该类来完成更多的工作:
class User
extend AttrEncrypted
attr_accessor :name
attr_encrypted :ssn, key: This is a key that is 256 bits!!
def load
# loads the stored data
end
def save
# saves the :name and :encrypted_ssn attributes somewhere (e.g. file
原创力文档

文档评论(0)