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

Management

What I look for in a CTO

There are eight things I always look for when deciding if someone would make a good CTO

Web Dev

Running Commands On Heroku

How to run commands on Heroku locally and from their web interface