title: AES , JAVA and javax.crypto.BadPaddingException: Given final block not properly padded
body: <p>I use the code below for decrypting with the correct key no problem but when try to brute force a key "I am not hacker, it is part of secuirty course" I get the padding error. I don't know what is wrong. Please help</p>
  
  <pre><code>RandomAccessFile f = new RandomAccessFile("partial-key.dat", "r");
     byte[] pkey = new byte[(int)f.length()];
     f.read(pkey);
  
     byte[] key = new byte[16];
  
     RandomAccessFile f1 = new RandomAccessFile("ciphertext2.dat", "r");
     byte[] cipher_text = new byte[(int)f1.length()];
     f.read(cipher_text);
  
  
      for(int copy=0; copy&lt;12;copy++){
          key[copy] = pkey[copy];
      }
      for(int br =0 ; br &lt;=4 ; br++){
          byte[] integ = intToByteArray(br);
          for(int ii =0 ; ii&lt;4; ii++){
              key[12+ii] = integ[ii];
          }
  
  
      SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
      Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
      cipher.init(Cipher.DECRYPT_MODE, skeySpec);
  
      byte[] text_byte = cipher.doFinal(cipher_text);
  </code></pre>