title: AES decryption not working for more than 16 bytes
body: <p>I am having a very strange problem using the AES encryption/decryption in Java. If I am encrypting/decrypting a string that is less then 16 bytes the cipher works fine but if I feed the cipher anything larger than 16 bytes I get the error "Given Final Block Not Padded Properly". I built some small code as an example:</p>
  
  <pre><code>package com.company;
  
  import javax.crypto.Cipher;
  import javax.crypto.spec.IvParameterSpec;
  import javax.crypto.spec.SecretKeySpec;
  
  public class Main {
  
      public static void main(String[] args) {
          try {
              Cipher aesEncrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
              Cipher aesDecrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
  
              SecretKeySpec key = new SecretKeySpec("ABCDEQWERTASDFGA".getBytes(), "AES");
  
              IvParameterSpec ivSpec = new IvParameterSpec(new byte[16]);
  
              aesDecrypt.init(Cipher.DECRYPT_MODE, key, ivSpec);
              aesEncrypt.init(Cipher.ENCRYPT_MODE, key, ivSpec);
  
              byte[] message = "Hello".getBytes();
  
              aesEncrypt.update(message);
  
              byte[] encrypted = aesEncrypt.doFinal();
  
              aesDecrypt.update(encrypted);
  
              byte[] decrypted = aesDecrypt.doFinal();
  
              System.out.println(new String(decrypted, "UTF-8"));
          }
          catch (Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>When the byte[] message is "Hello" the encryption/decryption works fine but when I change it to "HelloMyBabyHelloMyDarling" it throws the exception. Does anyone know what I am doing wrong here?</p>