title: InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null)
body: <p>I have two classes, one is main class and another is the implementation of AES.</p>
  
  <p>However, in my AES class i have a method to decrypt a string, but whenever i run it, it gives an exception</p>
  
  <p>My encryption method works just fine but my decryption method doesn't work as expected.</p>
  
  <p>The code</p>
  
  <pre><code>private Cipher aesCipherForDecryption;
  String strDecryptedText = new String();
  
  public String decryptAES(final String ciphertext) {
  
      try {
  
          aesCipherForDecryption = Cipher.getInstance("AES/CBC/PKCS5PADDING");
          aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iV));
          byte[] byteDecryptedText = aesCipherForDecryption.doFinal(byteCipherText);
          strDecryptedText = new String(byteDecryptedText);
  
      } catch (IllegalBlockSizeException e) {
          System.out.print("IllegalBlockSizeException " +e);
      } catch (BadPaddingException e) {
          System.out.print("BadPaddingException "+e);
      } catch (NoSuchAlgorithmException e) {
          System.out.print("NoSuchAlgorithmException "+ e);
      } catch (NoSuchPaddingException e) {
          System.out.print("NoSuchPaddingException "+e);
      } catch (InvalidKeyException e) {
          System.out.print("InvalidKeyException "+e);
      } catch (InvalidAlgorithmParameterException e) {
          System.out.print("InvalidAlgorithmParameterException "+e);
      }
  
      System.out.println("\nDecrypted Text message is " + strDecryptedText);
      return strDecryptedText;
  }
  </code></pre>
  
  <p>The error this method outputs is</p>
  
  <blockquote>
    <p>InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null)</p>
  </blockquote>
  
  <p>UPDATE #1:</p>
  
  <p>So i have updated the code as the following</p>
  
  <pre><code>public String decryptAES(byte[] ciphertext) {
      String strDecryptedText = new String();
          try {
              byte[] byteDecryptedText = aesCipherForDecryption.doFinal(ciphertext);
  
              strDecryptedText = new String(byteDecryptedText);
  
          } catch (IllegalBlockSizeException e) {
              System.out.print("IllegalBlockSizeException "+e);
              e.printStackTrace();
          } catch (BadPaddingException e) {
              System.out.print("BadPaddingException "+e);
              e.printStackTrace();
          }
  
      System.out.println("\nDecrypted Text message is " + strDecryptedText);
      return strDecryptedText;
  }    
  </code></pre>
  
  <p>and in the main class i have this line</p>
  
  <pre><code>byte [] byteciphertext = ciphertext.getBytes();
  </code></pre>
  
  <p>just to convert the string to bytes</p>
  
  <p>is it correct? i'm still having </p>
  
  <pre><code>IllegalBlockSizeException javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipherjavax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
  </code></pre>
  
  <p>Could someone help me fix this issue?</p>
  
  <p>Thank you.</p>