Module: AttrEncrypted

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Defined in:
lib/attr_encrypted.rb,
lib/attr_encrypted/version.rb,
lib/attr_encrypted/adapters/active_record.rb

Overview

Adds attr_accessors that encrypt and decrypt an object’s attributes

Defined Under Namespace

Modules: ActiveRecord, ClassMethods

Constant Summary collapse

VERSION =
"1.3.42"

Instance Method Summary collapse

Instance Method Details

#decrypt(attribute, encrypted_value) ⇒ Object

Decrypts a value for the attribute specified using options evaluated in the current object’s scope

Example

class User
  attr_accessor :secret_key
  attr_encrypted :email, :key => :secret_key

  def initialize(secret_key)
    self.secret_key = secret_key
  end
end

@user = User.new('some-secret-key')
@user.decrypt(:email, 'SOME_ENCRYPTED_EMAIL_STRING')


316
317
318
# File 'lib/attr_encrypted.rb', line 316

def decrypt(attribute, encrypted_value)
  self.class.decrypt(attribute, encrypted_value, evaluated_attr_encrypted_options_for(attribute))
end

#encrypt(attribute, value) ⇒ Object

Encrypts a value for the attribute specified using options evaluated in the current object’s scope

Example

class User
  attr_accessor :secret_key
  attr_encrypted :email, :key => :secret_key

  def initialize(secret_key)
    self.secret_key = secret_key
  end
end

@user = User.new('some-secret-key')
@user.encrypt(:email, '[email protected]')


335
336
337
# File 'lib/attr_encrypted.rb', line 335

def encrypt(attribute, value)
  self.class.encrypt(attribute, value, evaluated_attr_encrypted_options_for(attribute))
end