Class: ActiveRecord::Coders::Encryptors::AES

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/coders/encryptors/aes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AES

Returns a new instance of AES.



5
6
7
8
9
10
11
12
# File 'lib/active_record/coders/encryptors/aes.rb', line 5

def initialize(options = {})
  password = options[:password]
  key_length = options[:key_length] || 256
  binary = !!options[:binary]

  @cipher = ::Gibberish::AES.new(password, key_length)
  @options = { binary: binary }
end

Instance Attribute Details

#cipherObject (readonly)

Returns the value of attribute cipher.



3
4
5
# File 'lib/active_record/coders/encryptors/aes.rb', line 3

def cipher
  @cipher
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/active_record/coders/encryptors/aes.rb', line 3

def options
  @options
end

Instance Method Details

#dump(data) ⇒ Object



14
15
16
17
18
# File 'lib/active_record/coders/encryptors/aes.rb', line 14

def dump(data)
  cipher.encrypt(data, options)
rescue
  String.new
end

#load(data) ⇒ Object



20
21
22
23
24
# File 'lib/active_record/coders/encryptors/aes.rb', line 20

def load(data)
  cipher.decrypt(data, options)
rescue
  nil
end