Skip to content

Instantly share code, notes, and snippets.

@emboss
Created December 15, 2011 23:09
Show Gist options
  • Save emboss/1483407 to your computer and use it in GitHub Desktop.
Save emboss/1483407 to your computer and use it in GitHub Desktop.
IV "magic"
require 'openssl'
data = "letest" * 10
cipher = OpenSSL::Cipher::AES128.new('CBC')
cipher.encrypt
key = OpenSSL::Random.random_bytes(cipher.key_len)
cipher.key = key
cipher.iv = "OpenSSL for Ruby rulez!"
enc = cipher.update(data) + cipher.final
cipher.reset
cipher.decrypt
cipher.key = key
cipher.iv = "OpenSSL for Ruby is OK, but I rule!"
dec = cipher.update(enc) + cipher.final
puts dec == data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment