Sha256: f3a8e9fc5039269e9c66a2bd3e76ef7b7b398538eb36bc609ea8b65f24cb8fc6

Contents?: true

Size: 711 Bytes

Versions: 27

Compression:

Stored size: 711 Bytes

Contents

module Avo
  module Services
    class EncryptionService
      class << self
        def encrypt(...)
          new(...).encrypt
        end

        def decrypt(...)
          new(...).decrypt
        end
      end

      def initialize(message:, purpose:, **kwargs)
        @message = message
        @purpose = purpose
        @crypt = ActiveSupport::MessageEncryptor.new(encryption_key, **kwargs)
      end

      def encrypt
        @crypt.encrypt_and_sign(@message, purpose: @purpose)
      end

      def decrypt
        @crypt.decrypt_and_verify(@message, purpose: @purpose)
      end

      private

      def encryption_key
        Rails.application.secret_key_base[0..31]
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
avo-3.14.3 lib/avo/services/encryption_service.rb
avo-3.14.2 lib/avo/services/encryption_service.rb
avo-3.14.1 lib/avo/services/encryption_service.rb
avo-3.14.0 lib/avo/services/encryption_service.rb
avo-3.13.7 lib/avo/services/encryption_service.rb
avo-3.13.6 lib/avo/services/encryption_service.rb
avo-3.13.5 lib/avo/services/encryption_service.rb
avo-3.13.4 lib/avo/services/encryption_service.rb
avo-3.13.3 lib/avo/services/encryption_service.rb
avo-3.13.2 lib/avo/services/encryption_service.rb
avo-3.13.1 lib/avo/services/encryption_service.rb
avo-3.13.0 lib/avo/services/encryption_service.rb
avo-3.12.0 lib/avo/services/encryption_service.rb
avo-3.11.10 lib/avo/services/encryption_service.rb
avo-3.11.9 lib/avo/services/encryption_service.rb
avo-3.11.8 lib/avo/services/encryption_service.rb
avo-3.11.7 lib/avo/services/encryption_service.rb
avo-3.11.6 lib/avo/services/encryption_service.rb
avo-3.11.5 lib/avo/services/encryption_service.rb
avo-3.11.4 lib/avo/services/encryption_service.rb