title: javax.crypto.BadPaddingException AES
body: <p>I am using <code>AESCrypt</code> <code>(gradle :compile 'com.scottyab:aescrypt:0.0.1')</code>
  to encrypt and decrypt the data.</p>
  
  <pre><code>  TextView  tv=(TextView)findViewById(R.id.demotext);
      String encrypted="",decrypted="";
      try {
          encrypted = AESCrypt.encrypt("password","This is the best thing to go by");
  
          decrypted = AESCrypt.decrypt("password",encrypted);
      } catch (GeneralSecurityException e) {
          e.printStackTrace();
      }
      System.out.println("EncryptedData:"+encrypted);
      System.out.println("DecryptedData:"+decrypted);
      tv.setText("Encrypted:"+encrypted +"\n"+"Decrypted:"+decrypted);
  </code></pre>
  
  <p>The code works perfectly fine in this case, I get the same input as decrypted text. </p>
  
  <p>But, when I try to use already encrypted string using the same method (<strong>AES</strong>) from the site <a href="http://aesencryption.net/" rel="nofollow noreferrer">http://aesencryption.net/</a> as shown in the screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/OqQkW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OqQkW.png" alt="enter image description here"></a></p>
  
  <p>And copy paste that encrypted text like:</p>
  
  <pre><code>decrypted = AESCrypt.decrypt("password","sttA+FbNm3RkTovjHI8CcAdStXiMl45s29Jqle+y+pA=");
  </code></pre>
  
  <p>And then run the code then I get error saying :</p>
  
  <pre><code>javax.crypto.BadPaddingException: error:1e06b065:Cipher functions:EVP_DecryptFinal_ex:BAD_DECRYPT
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kEAC4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kEAC4.png" alt="enter image description here"></a></p>
  
  <p>But when I use the decrypted text into the same site it works fine as shown in the screenshot below.</p>
  
  <p><a href="https://i.stack.imgur.com/NICy2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NICy2.png" alt="enter image description here"></a></p>
  
  <pre><code>private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
          SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
          Cipher cipher = Cipher.getInstance("AES");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec);
          byte[] decrypted = cipher.doFinal(encrypted);
          return decrypted;
      }
  </code></pre>