Class: SSEncryptor::Encryptor
- Inherits:
-
Object
- Object
- SSEncryptor::Encryptor
- Defined in:
- lib/SSEncryptor/encryptor.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Instance Method Summary collapse
- #decrypt(data) ⇒ Object
- #encrypt(data) ⇒ Object
-
#initialize(key, options = {}) ⇒ Encryptor
constructor
A new instance of Encryptor.
- #process_and_set_key(key) ⇒ Object
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, = {}) @algorithm = [:algorithm] || 'AES-256-CBC' @iv ||= [:iv] process_and_set_key(key) end |
Instance Attribute Details
#algorithm ⇒ Object (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 |