A simple cryptography to encode and decode a payload based on OpenSSL::Cipher class SimpleCryptography SECRET = "secretkey" def self.encode payload cipher = OpenSSL::Cipher.new('AES-128-CBC').encrypt cipher.key = Digest::SHA1.hexdigest(SECRET).unpack('B16').first s = cipher.update(payload) + cipher.final s.unpack('H*')[0].upcase end def self.decode enrypted_payload cipher = OpenSSL::Cipher.new('AES-128-CBC').decrypt cipher.key = Digest::SHA1.hexdigest(SECRET).unpack('B16').first s = [payload].pack("H*").unpack("C*").pack("c*") cipher.update(s) + cipher.final end end Example payload = "1234567890" # encode enrypted_payload = SimpleCryptography.encode(payload) # decode decrypted_payload = SimpleCryptography.decode(enrypted_payload) # compare the decoded payload with actual payload decrypted_payload == payload