title: javax.crypto.BadPaddingException: Given final block not properly padded - Android
body: <p>I have read about this error but can't seem to get anything working.</p>
  
  <p>The function of AES decrypt is:</p>
  
  <pre><code>  public static byte[] decrypted_Data(byte[] crypt) throws Exception {
  
    String seed = "SuperSecretPassword";
  
    KeyGenerator keygen = KeyGenerator.getInstance("AES");
  
    SecureRandom secrand = SecureRandom.getInstance("SHA1PRNG");
  
    secrand.setSeed(seed.getBytes());
  
    keygen.init(128, secrand);
  
    SecretKey seckey = keygen.generateKey();
  
    byte[] rawKey = seckey.getEncoded();
  
   SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
  
   Cipher cipher = Cipher.getInstance("AES");
  
   cipher.init(Cipher.DECRYPT_MODE, skeySpec);
  
   byte[] decrypted = cipher.doFinal(crypt);
  
    return decrypted;
  }
  </code></pre>
  
  <p>The function of encrypt is just the same except for      </p>
  
  <pre><code>cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
  </code></pre>
  
  <p>I am calling these functions as follows on Android:</p>
  
  <pre><code>BufferedInputStream bis = new BufferedInputStream(photoStream);
  
  byte[] mybytearray = new byte[photoStream.available()];
  
  mybytearray = encrypted_Data(mybytearray);
  </code></pre>
  
  <p>And on the server as follows:</p>
  
  <pre><code>   byte[] mybytearray = new byte[10000000];
  
     mybytearray_1 = decrypted_Data(mybytearray_1);
  </code></pre>
  
  <p>This is the first time i use these encryption functions, what am I doing wrong as I am receiving:</p>
  
  <pre><code>javax.crypto.BadPaddingException: Given final block not properly padded 
  </code></pre>