title: Does AES/CBC really require IV parameter?
body: <p>I am writing a simple app to encrypt my message using AES / CBC (mode). As my understanding CBC mode requires IV parameter but I don't know why my code work without IV parameter used. Anyone can explain why? Thanks.</p>
  <p><strong>The encrypted message printed: T9KdWxVZ5xStaisXn6llfg==    without exception.</strong></p>
  <pre class="lang-java prettyprint-override"><code>public class TestAES {
  
      public static void main(String[] args) {
  
          try {
              byte[] salt = new byte[8];
              new SecureRandom().nextBytes(salt);
  
              SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(&quot;PBKDF2WithHmacSHA1&quot;);
              KeySpec keySpec = new PBEKeySpec(&quot;myPassword&quot;.toCharArray(), salt, 100, 128);
  
              SecretKey tmp = keyFactory.generateSecret(keySpec);
              SecretKeySpec key = new SecretKeySpec(tmp.getEncoded(), &quot;AES&quot;);
  
              Cipher enCipher = Cipher.getInstance(&quot;AES/CBC/PKCS5Padding&quot;);
              enCipher.init(Cipher.ENCRYPT_MODE, key);
  
              // enCipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
  
              byte[] cipherBytes = enCipher.doFinal(&quot;myMessage&quot;.getBytes());
              String cipherMsg = BaseEncoding.base64().encode(cipherBytes);
  
              System.out.println(&quot;Encrypted message: &quot; + cipherMsg);
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
      }
  }
  </code></pre>