ea8e9901f4
Your branch is behind 'origin/strong-params' by 1 commit, and can be fast-forwarded. I'll pull to catch up after this commit Change code to whitelist params Remove attr_accessible lines Add strong_params to Gemfile, since this branch is still on Rails 3 Mixin to ActiveRecord::Base ActiveModel::ForbiddenAttributesProtection Use an initializer for the mixin
42 lines
892 B
Ruby
42 lines
892 B
Ruby
class WorkInfo < ActiveRecord::Base
|
|
belongs_to :user
|
|
has_one :key_management, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
|
#before_save :encrypt_ssn
|
|
|
|
# We should probably use this
|
|
def last_four
|
|
"***-**-" << self.decrypt_ssn[-4,4]
|
|
end
|
|
|
|
def encrypt_ssn
|
|
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
|
aes.encrypt
|
|
aes.key = key
|
|
aes.iv = iv if iv != nil
|
|
self.encrypted_ssn = aes.update(self.SSN) + aes.final
|
|
self.SSN = nil
|
|
end
|
|
|
|
def decrypt_ssn
|
|
aes = OpenSSL::Cipher::Cipher.new(cipher_type)
|
|
aes.decrypt
|
|
aes.key = key
|
|
aes.iv = iv if iv != nil
|
|
aes.update(self.encrypted_ssn) + aes.final
|
|
end
|
|
|
|
def key
|
|
raise "Key Missing" if !(KEY)
|
|
KEY
|
|
end
|
|
|
|
def iv
|
|
raise "No IV for this User" if !(self.key_management.iv)
|
|
self.key_management.iv
|
|
end
|
|
|
|
def cipher_type
|
|
'aes-256-cbc'
|
|
end
|
|
end
|