title: AES 256 bit encryption
body: <p>I am trying to encrypt some data using AES 256 bit encryption however I keep getting the error - </p>
  
  <p>Error while encrypting: java.security.InvalidKeyException: Illegal key size or default parameters</p>
  
  <p>My code is - </p>
  
  <pre><code>key = "abcd123456789kjd";
  byteKey = key.getBytes();
  MessageDigest sha = MessageDigest.getInstance("SHA-256");
  byteKey = sha.digest(byteKey);
  byteKey = Arrays.copyOf(byteKey, 32); // use only first 256 bit
  secretKey = new SecretKeySpec(byteKey, "AES");
  Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE, secretKey);
  </code></pre>
  
  <p>Can someone please help figure out why the error is coming. It is working if I make it into 128 bit instead of 256 bit.</p>