title: javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
body: <p>I'm working on a android project in which I have to decrypt string from a file in PHP server, encryption was done using PHP.(AES 128 algorithm)</p>
  
  <p>Encryption Code:</p>
  
  <pre><code> function aes128Encrypt($key, $data) {
        $key = md5($key);
        return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, str_repeat("\0", 16));
      }
  </code></pre>
  
  <p>My code for getting string from URL:</p>
  
  <pre><code>String myUri = "http://www.example.com/lib2.php";
  HttpClient httpClient = new DefaultHttpClient();
  HttpGet get = new HttpGet(myUri);
  
  HttpResponse response = httpClient.execute(get);
  
  String bodyHtml = "";
  String xmlFile = "";
  bodyHtml = EntityUtils.toString(response.getEntity());
  System.out.println(bodyHtml);
  xmlFile = decrypt(bodyHtml);
  System.out.println(xmlFile);
  </code></pre>
  
  <p>decrypt() method:</p>
  
  <pre><code>public static String decrypt(String encData) throws Exception
      {
          Key key = generateKey();
  
          Cipher c = Cipher.getInstance(algo + "/CBC/PKCS7Padding");
  
          //Cipher c = Cipher.getInstance(algo);
  
          IvParameterSpec ivSpec = new IvParameterSpec(ivbytes);
  
          c.init(Cipher.DECRYPT_MODE, key , ivSpec);
  
          //byte[] decValue = Base64.decode(encData , Base64.NO_PADDING);
  
          //byte[] decFin = Base64.decode(decValue, Base64.NO_PADDING);
  
          //byte[] decFinal = c.doFinal(decValue);
  
          byte[] decFinal = c.doFinal(encData.getBytes());
  
          String getAns = new String(decFinal, "UTF8");
  
          return getAns;
      }
  </code></pre>
  
  <p>In generateKey():</p>
  
  <pre><code>public static Key generateKey()
      {
  
          try {
              MessageDigest digest = java.security.MessageDigest
                      .getInstance("MD5");
  
              digest.update(myChar.getBytes());
  
              key1 = digest.digest();
  
          } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();
          }
  
  
  
          Key key = new SecretKeySpec(key1,algo);     
          return key;
      }
  }
  </code></pre>
  
  <p>The Logcat shows below exception:</p>
  
  <pre><code>javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
  </code></pre>
  
  <p>at the line <code>c.doFinal()</code></p>
  
  <p>The Codes I'v commented out are also the codes I'v used to check. What is wrong with this code?. Any help will be appreciated.</p>