Created
December 15, 2011 10:57
-
-
Save emboss/1480700 to your computer and use it in GitHub Desktop.
What's the default IV for Cipher?
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 = "lesecret" * 10 | |
cipher = OpenSSL::Cipher::AES256.new("CBC") | |
key = OpenSSL::Random.random_bytes(cipher.key_len) | |
cipher.encrypt | |
cipher.key = key | |
enc = cipher.update(data) + cipher.final | |
dec = OpenSSL::Cipher::AES256.new("CBC") | |
dec.decrypt | |
dec.key = key | |
dec.iv = "\0" * cipher.iv_len #this is the default IV, implied by OpenSSL itself | |
text = dec.update(enc) + dec.final | |
puts text == data # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment