Sha256: 03bb44274679f8a59de6b2761d4c5025b89ac1c7cf6387af550c9fe3f5a0b3ff

Contents?: true

Size: 686 Bytes

Versions: 69

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # Service to encrypt and decrypt metadata
    class DataEncryptor
      attr_reader :secret

      def initialize(args = {})
        @secret = args.fetch(:secret) || "default"
        @key = ActiveSupport::KeyGenerator.new(secret).generate_key(
          Rails.application.secrets.secret_key_base, ActiveSupport::MessageEncryptor.key_len
        )
        @encryptor = ActiveSupport::MessageEncryptor.new(@key)
      end

      def encrypt(data)
        @encryptor.encrypt_and_sign(data)
      end

      def decrypt(encrypted_data)
        @encryptor.decrypt_and_verify(encrypted_data)
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.4 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.27.9 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.29.0 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.3 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.27.8 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.29.0.rc4 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.29.0.rc3 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.29.0.rc2 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.29.0.rc1 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.2 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.27.7 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.1 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.27.6 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.26.10 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.26.9 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.0 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.27.5 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.0.rc5 app/services/decidim/initiatives/data_encryptor.rb
decidim-initiatives-0.28.0.rc4 app/services/decidim/initiatives/data_encryptor.rb