Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created November 22, 2011 11:39
Show Gist options
  • Save joeljunstrom/1385477 to your computer and use it in GitHub Desktop.
Save joeljunstrom/1385477 to your computer and use it in GitHub Desktop.
module Encryptor
def encryptor(salt)
ActiveSupport::MessageEncryptor.new(Digest::SHA1.hexdigest(salt + Configuration.encryption_salt))
end
end
class Thing
include Encryptor
def hash_new_key
self.key_salt = ActiveSupport::SecureRandom.base64(16)
self.key_hash = encryptor(key_salt).encrypt(@key)
end
def unhash_key
@key = if key_hash.present?
encryptor(key_salt).decrypt(key_hash)
else
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment