class ActiveEncryption::Encryptor
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)
Attributes
encryption_setting[R]
Public Class Methods
new(encryption_setting, service = nil)
click to toggle source
# File lib/active_encryption/encryptor.rb, line 18 def initialize(encryption_setting, service = nil) @encryption_setting = encryption_setting @service = service end
Public Instance Methods
decrypt(data, purpose: nil)
click to toggle source
# 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)
click to toggle source
:reek: LongParameterList is required to map to encrypt_and_sign
# 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
Private Instance Methods
service()
click to toggle source
# File lib/active_encryption/encryptor.rb, line 46 def service @service ||= ActiveSupport::MessageEncryptor.new( encryption_setting.key, cipher: encryption_setting.cipher, digest: encryption_setting.digest, serializer: encryption_setting.serializer ) end