Created
December 15, 2011 23:09
-
-
Save emboss/1483407 to your computer and use it in GitHub Desktop.
IV "magic"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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