Class: SSEncryptor::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/SSEncryptor/encryptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ Encryptor

Returns a new instance of Encryptor.



7
8
9
10
11
# File 'lib/SSEncryptor/encryptor.rb', line 7

def initialize(key, options = {})
  @algorithm = options[:algorithm] || 'AES-256-CBC'
  @iv ||= options[:iv]
  process_and_set_key(key)
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



5
6
7
# File 'lib/SSEncryptor/encryptor.rb', line 5

def algorithm
  @algorithm
end

Instance Method Details

#decrypt(data) ⇒ Object



22
23
24
# File 'lib/SSEncryptor/encryptor.rb', line 22

def decrypt(data)
  call(:decrypt, data)
end

#encrypt(data) ⇒ Object



18
19
20
# File 'lib/SSEncryptor/encryptor.rb', line 18

def encrypt(data)
  call(:encrypt, data)
end

#process_and_set_key(key) ⇒ Object



13
14
15
16
# File 'lib/SSEncryptor/encryptor.rb', line 13

def process_and_set_key(key)
  key_len = OpenSSL::Cipher.new(@algorithm).key_len
  @key = key.rjust(key_len, key)[0..key_len - 1]
end