Module: OffsitePayments::Integrations::SagePayForm::Encryption

Included in:
Helper, Notification
Defined in:
lib/offsite_payments/integrations/sage_pay_form.rb

Instance Method Summary collapse

Instance Method Details

#sage_decrypt(ciphertext, key) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 35

def sage_decrypt(ciphertext, key)
  ciphertext = ciphertext[1..-1] # remove @ symbol at the beginning of a string
  cipher(:decrypt, key, ciphertext)
rescue OpenSSL::Cipher::CipherError => e
  return '' if e.message == 'wrong final block length'
  raise
end

#sage_encrypt(plaintext, key) ⇒ Object



30
31
32
33
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 30

def sage_encrypt(plaintext, key)
  encrypted = cipher(:encrypt, key, plaintext)
  "@#{encrypted.upcase}"
end

#sage_encrypt_salt(min, max) ⇒ Object



43
44
45
46
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 43

def sage_encrypt_salt(min, max)
  length = rand(max - min + 1) + min
  SecureRandom.base64(length + 4)[0, length]
end