Class: ActiveEncryption::Encryptor
- Inherits:
-
Object
- Object
- ActiveEncryption::Encryptor
- Defined in:
- lib/active_encryption/encryptor.rb
Overview
The ActiveEncryption::Encryptor is an abstraction class around ActiveSupport::MessageEncryptor
Usage:
encryptor = ActiveEncryption::Encryptor.new(encryption_setting) encrypted_data = encryptor.encrypt(data) data = encryptor.decrypt(encrypted_data)
Instance Attribute Summary collapse
-
#encryption_setting ⇒ Object
readonly
Returns the value of attribute encryption_setting.
Instance Method Summary collapse
- #decrypt(data, purpose: nil) ⇒ Object
-
#encrypt(data, expires_at: nil, expires_in: nil, purpose: nil) ⇒ Object
:reek:LongParameterList is required to map to encrypt_and_sign.
-
#initialize(encryption_setting, service = nil) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
#initialize(encryption_setting, service = nil) ⇒ Encryptor
Returns a new instance of Encryptor.
18 19 20 21 |
# File 'lib/active_encryption/encryptor.rb', line 18 def initialize(encryption_setting, service = nil) @encryption_setting = encryption_setting @service = service end |
Instance Attribute Details
#encryption_setting ⇒ Object (readonly)
Returns the value of attribute encryption_setting.
16 17 18 |
# File 'lib/active_encryption/encryptor.rb', line 16 def encryption_setting @encryption_setting end |
Instance Method Details
#decrypt(data, purpose: nil) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/active_encryption/encryptor.rb', line 35 def decrypt(data, purpose: nil) return nil unless data service.decrypt_and_verify( data, purpose: purpose ) end |
#encrypt(data, expires_at: nil, expires_in: nil, purpose: nil) ⇒ Object
:reek:LongParameterList is required to map to encrypt_and_sign
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_encryption/encryptor.rb', line 24 def encrypt(data, expires_at: nil, expires_in: nil, purpose: nil) return nil unless data service.encrypt_and_sign( data, expires_at: expires_at, expires_in: expires_in, purpose: purpose ) end |