title: What causes the error "java.security.InvalidKeyException: Parameters missing"?
body: <p>I'm trying to encrypt and decrypt a string using AES but getting an error I don't know how to resolve. This is the code:</p>
  
  <pre><code>public class EncryptionTest{
  
  public static void main(String[] args) {        
      String encrypt = new String(encrypt("1234567890123456"));
      System.out.println("decrypted value:" + (decrypt("ThisIsASecretKey",encrypt)));
  }
  
  public static String encrypt(String value) {
      try {
          byte[] raw = new byte[]{'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y'};
          SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
          Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
          cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
          byte[] encrypted = cipher.doFinal(value.getBytes());
          System.out.println("encrypted string:" + (new String(encrypted)));
          return new String(skeySpec.getEncoded());
      } catch (Exception ex) {
          ex.printStackTrace();
      }
      return null;
  }
  
  public static String decrypt(String key, String encrypted) {
      try {
          SecretKeySpec skeySpec = new SecretKeySpec(Base64.decodeBase64(key), "AES");
          Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
          cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(skeySpec.getEncoded(),"AES"));
              (*)
          byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
          original.toString();
      } catch (Exception ex) {
          ex.printStackTrace();
      }
      return null;
  }  
  }
  </code></pre>
  
  <p>When I run it the "decription" values is null. It fails before the (***) !!</p>
  
  <p>It gives me an exception:</p>
  
  <pre>
  java.security.InvalidKeyException: Parameters missing
      at com.sun.crypto.provider.CipherCore.init(CipherCore.java:388)
      at com.sun.crypto.provider.AESCipher.engineInit(AESCipher.java:186)
      at javax.crypto.Cipher.implInit(Cipher.java:787)
      at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
      at javax.crypto.Cipher.init(Cipher.java:1213)
      at javax.crypto.Cipher.init(Cipher.java:1153)
      at firma.XmlEncryptionTest.decrypt(EncryptionTest.java:63)
      at firma.XmlEncryptionTest.main(EncryptionTest.java:41)
  </pre>
  
  <p>where the line 63 is the one before (***). I don't know what am I doing wrong and how to solve. I looked around on the internet but without finding out what coul be that missing parameter</p>