title: Why OpenSSL::PKCS5.pbkdf2_hmac_sha1 generates key with different length?
body: <p>I'm using Rails 3.2 and are trying to generate a key and IV from <strong>pbkdf2_hmac_sha1</strong> function in order to crypto something using AES-CBC 256.</p>
  
  <p>The code I use to generate it is:</p>
  
  <pre><code>require "openssl"
  require "base64"
  require "digest"
  require "securerandom"
  
  @chave = "fd5d148867091d7595c388ac0dc50bb465052b764c4db8b4b4c3448b52ee0b33df16975830acca82"
  
  cipher = OpenSSL::Cipher.new("AES-256-CBC")
  key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(@chave, salt, 2000, cipher.key_len+cipher.iv_len)
  key = key_iv[0, cipher.key_len]
  iv  = key_iv[cipher.key_len, cipher.iv_len]
  </code></pre>
  
  <p>I generate a random salt using SecureRandom.urlsafe_base64 and noticed that sometimes the IV length (which should be 16 bytes) is 15 bytes rather than 16 bytes when I use some salts.</p>
  
  <p>For instance, if you have a salt = "lzbH78AwVK7U1eo-ephK6A", it generates a IV = "604ff394b52e79255fa35b081684b0" (15 bytes long).</p>
  
  <p>Can someone have a clue of what I'm doing wrong?</p>