Skip to content

Instantly share code, notes, and snippets.

@guivinicius
Created January 29, 2015 16:04
Show Gist options
  • Save guivinicius/6888adaf30924621c4ef to your computer and use it in GitHub Desktop.
Save guivinicius/6888adaf30924621c4ef to your computer and use it in GitHub Desktop.
class EncDec
KEY = "FA 0E 3C 9B 4F A2 C7 AA 37 0F CA 9B 5A 91 64 08"
IV = "AA AD 8B 4C 00 E1 3F 53 B8 E7 16 BC B5 F4 D1 B9"
attr_reader :cipher, :message, :key, :iv
def initialize(message, key = nil, iv = nil)
@key, @iv = key, iv
@cipher = OpenSSL::Cipher::AES128.new(:CBC)
@message = message
cipher.key = key || KEY.delete(' ')
cipher.iv = iv || IV.delete(' ')
end
def decrypt
cipher.decrypt
cipher.update(message) + cipher.final
end
def encrypt
cipher.encrypt
cipher.update(message) + cipher.final
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment