Sha256: 2c58dbd5c1fcda66638bd666502b8cfbfe02fe0121d769b2e778f18ef0ecd779

Contents?: true

Size: 935 Bytes

Versions: 27

Compression:

Stored size: 935 Bytes

Contents

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module SagePayForm
        module Encryption
          def sage_encrypt(plaintext, key)
            ActiveSupport::Base64.encode64s(sage_encrypt_xor(plaintext, key))
          end

          def sage_decrypt(ciphertext, key)
            sage_encrypt_xor(ActiveSupport::Base64.decode64(ciphertext), key)
          end
          
          def sage_encrypt_salt(min, max)
            length = rand(max - min + 1) + min
            SecureRandom.base64(length + 4)[0, length]
          end

          private

          def sage_encrypt_xor(data, key)
            raise 'No key provided' if key.blank?
            
            key *= (data.length.to_f / key.length.to_f).ceil
            key = key[0, data.length]

            data.bytes.zip(key.bytes).map { |b1, b2| (b1 ^ b2).chr }.join
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 8 rubygems

Version Path
activemerchant-1.20.2 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.20.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.20.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.18.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
fishman-activemerchant-1.18.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.18.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.17.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
yetanothernguyen-activemerchant-1.16.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.16.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
gonow-activemerchant-1.15.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
bitfluent-activemerchant-1.15.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-kiddy-1.15.0.kiddy.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-kiddy-1.15.0.kiddy lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.15.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.14.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.13.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.12.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.12.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.11.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.10.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb