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

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.