Sha256: f7dc345038648762aa3a304865f1a34157751476f2d2c61cd4c66d18f4e152e7
Contents?: true
Size: 1014 Bytes
Versions: 13
Compression:
Stored size: 1014 Bytes
Contents
require 'digest/sha1' module Sentry class ShaSentry @@salt = 'salt' attr_accessor :salt # Encrypts data using SHA. def encrypt(data) self.class.encrypt(data + salt.to_s) end # Initialize the class. # Used by ActiveRecord::Base#generates_crypted to set up as a callback object for a model def initialize(attribute = nil) @attribute = attribute end # Performs encryption on before_validation Active Record callback def before_validation(model) return unless model.send(@attribute) model.send("crypted_#{@attribute}=", encrypt(model.send(@attribute))) end class << self # Gets the class salt value used when encrypting def salt @@salt end # Sets the class salt value used when encrypting def salt=(value) @@salt = value end # Encrypts the data def encrypt(data) Digest::SHA1.hexdigest(data + @@salt) end end end end
Version data entries
13 entries across 13 versions & 5 rubygems