Sha256: 8875dc59319dfd65f58303eb08cc28f9fa63aac7bc1df0881058da5f0479e333

Contents?: true

Size: 917 Bytes

Versions: 64

Compression:

Stored size: 917 Bytes

Contents

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

          def sage_decrypt(ciphertext, key)
            sage_encrypt_xor(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.bytesize.to_f / key.bytesize.to_f).ceil
            key = key[0, data.bytesize]

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

Version data entries

64 entries across 64 versions & 6 rubygems

Version Path
tanga_activemerchant-1.38.0.5 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.38.0.4 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.38.0.3 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.38.0.2 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.38.0.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.38.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
tanga_activemerchant-1.37.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.43.3 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.43.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.43.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.9 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.8 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.7 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.6 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.5 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.4 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.3 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.2 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.1 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb
activemerchant-1.42.0 lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb