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

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.

VS Code Web Dev

Select multiple lines in VS Code

How to select multiple lines to edit at once within VS Code