Creating a SagePay Encryption in Ruby

A SagePay encryption for Ruby that some folk might find useful

I’ve just had to create SagePay encryption in Ruby that isn’t well documented anywhere, eventually found an old broken gem that I was able to use for parts. Thought someone might find it useful!

  def self.encrypt(input, password)
    cipher = OpenSSL::Cipher.new('AES-128-CBC')
    cipher.send(:encrypt)
    cipher.key = password
    cipher.iv = password

    result = cipher.update(input) + cipher.final

    "@#{result.unpack('H*').first.upcase}"
  end

Recent posts View all

Web Dev

Updating payment method email addresses in Stripe

You can't update the email address associated with a payment method in Stripe via their dashboard, you need to use the Stripe CLI

Ruby

Irreversible Rails Migrations

What are irreversible migrations and how might we use them to our advantage?