title: AES decryption, IV length
body: <p>I'm trying to decrypt a string, but I'm getting the </p>
  
  <p><em>Specified initialization vector (IV) does not match the block size for this algorithm.</em></p>
  
  <p>I've been searching SO and the web for a while and I understand my IV is 32 bytes and should be 16 bytes, but I can't figure out how to achieve it. The string to get has been encrypted using AES/CBC/PKCS5Padding and my code (well, actually I've found it somewhere in the web) is</p>
  
  <pre><code>var btKey = Encoding.ASCII.GetBytes("7c6e1257d0e81ff55bda80cc904365ae");
  var btIV = Encoding.ASCII.GetBytes("cf5e4620455cd7190fcb53ede874f1a8");
  
  aesAlg.Key = btKey;
  aesAlg.IV = btIV;
  
  aesAlg.Padding = PaddingMode.PKCS7;
  
  // Create a decrytor to perform the stream transform.
  var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
  
  // Create the streams used for decryption.
  using (MemoryStream msDecrypt = new MemoryStream(encodedTicketAsBytes))
    {
      using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)){
        using (StreamReader srDecrypt = new StreamReader(csDecrypt))
        {
          // Read the decrypted bytes from the decrypting stream
          // and place them in a string.
          plainText = srDecrypt.ReadToEnd();
        }
      }
    }
  </code></pre>
  
  <p>What I don't understand is the use of the aesAlg.Padding, to be honest I couldn't find yet an easy, to my understanding, example of this in C#.</p>
  
  <p>Any help?,</p>
  
  <p>Thanks!!</p>