class EncryptedStringSerializer
def self.load(value)
value.to_s.blank? ? ” : decrypt(value)
end
def self.dump(value)
encrypt(value || ”)
end
private
def self.encrypt(value)
encryptor.encrypt_and_sign(value)
end
def self.decrypt(value)
encryptor.decrypt_and_verify(value)
end
def self.encryptor
@encryptor ||=ActiveSupport::MessageEncryptor.new(Settings.message_encryptor_key)
end
end
class UserAddress < ActiveRecord::Base
serialize :phone, EncryptedStringSerializer
serialize :first_name, EncryptedStringSerializer
serialize :last_name, EncryptedStringSerializer
serialize :country, EncryptedStringSerializer
serialize :state, EncryptedStringSerializer
serialize :city, EncryptedStringSerializer
serialize :address1, EncryptedStringSerializer
serialize :address2, EncryptedStringSerializer
serialize :zipcode, EncryptedStringSerializer
end