title: Input Length must be a multiple of 16 when decrypting with a padded cipher
body: <p>I have looked everywhere for an answer to this problem but it either doesn`t exist or im being stupid. Basically I have two methods, one to encrypt a string and one to decrypt. and in both I pass in a single string and an object of one of my classes which has the key in it. I have messed around with the placement of encoding and decoding base 64 and even not having it at all. I am at a loss. Can anyone provide any help? I have put my code for these two below:</p>
  <pre><code>public static String decrypt(String to_dec, Crypto crypt){
      try {
          Cipher chipher = Cipher.getInstance(&quot;AES&quot;);
          chipher.init(Cipher.DECRYPT_MODE, crypt.app_Crypto);
          byte[] text = to_dec.getBytes(StandardCharsets.UTF_8);
          text = chipher.doFinal(text);
          text = Base64.getDecoder().decode(text);
          String res = new String(text);
          return(res);
      }catch(Exception e){
          System.out.println(&quot;Error: Unable to decrypt data&quot;);
          System.out.println(e);
          return null;
      }
  }
  </code></pre>
  <p>as well as my method to encrypt:</p>
  <pre><code>public static String encrypt(String to_enc, Crypto crypt){
      try{
          Cipher chipher = Cipher.getInstance(&quot;AES&quot;);
          chipher.init(Cipher.ENCRYPT_MODE, crypt.app_Crypto);
          byte[] encrypt = Base64.getEncoder().encode(to_enc.getBytes(StandardCharsets.UTF_8));
          String text = new String(chipher.doFinal(encrypt));
          return(text);
      }catch(Exception e){
          System.out.println(&quot;Error: Unable to encrypt data&quot;);
          return null;
      }
  
  
  }
  </code></pre>
  <p>Edit: When switching where and when i decode/encode base64, sometimes it gives me a different error called badPaddingException, that the final block is not properly padded</p>