title: Ruby openssl lib - Why does AES-256-CBC decrypting gives readable data without the correct IV?
body: <p>Given the following script</p>
  
  <pre><code>require "openssl"
  require "securerandom"
  
  key = SecureRandom.random_bytes(32)
  iv = SecureRandom.random_bytes(16)
  
  aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
  aes.encrypt
  aes.key = key
  aes.iv = iv
  
  crypted = aes.update("a"*50)+aes.final
  
  aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
  aes.decrypt
  aes.key = key
  aes.iv = iv
  
  puts aes.update(crypted)+aes.final
  
  aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
  aes.decrypt
  aes.key = key
  
  puts aes.update(crypted)+aes.final
  </code></pre>
  
  <p>I get the following output (e.g.):</p>
  
  <pre><code>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  ���y��f{�K~:y��aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  </code></pre>
  
  <p>Does I need to perform these CBC-style XOR operations, block size caring etc. on my own? I cannot find any example which is not simply calling the update function passing the string which should be decrypted. I already tried to add .dup to all string assignments to prevent inplace edit issues. What is going on here?</p>
  
  <p>Environment: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]</p>