making sure this is up to date

This commit is contained in:
cktricky
2014-03-14 14:00:51 -04:00
parent ec8a187833
commit d0e825fc17
4 changed files with 40 additions and 7 deletions
+1
View File
@@ -1,5 +1,6 @@
class KeyManagement < ActiveRecord::Base
attr_accessible :iv, :user_id
belongs_to :work_info
belongs_to :user
end
+34 -3
View File
@@ -64,8 +64,6 @@ private
end
=end
def assign_user_id
unless @skip_user_id_assign.present? || self.user_id.present?
user = User.order("user_id").last
@@ -82,9 +80,42 @@ private
end
end
# Added a re-usable encryption routine, shouldn't be an issue!
def encrypt_sensitive_value(val="")
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
# Should be able to just re-use the same key we already have!
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
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
#self[column] =
end while User.exists?(column => self[column])
end