title: Cannot decrypt encrypted file in android lollipop
body: <p>I have an encrypt/decrypt mechanism for downloaded files in my app.</p>
  
  <p>This mechanism works in all android devices and versions prior to android 5.0-lollipop.</p>
  
  <p>Here is decryption process:</p>
  
  <pre><code>cipher.init(Cipher.DECRYPT_MODE, key);
  fileInputStream = new FileInputStream(file);
  cipherInputStream = new CipherInputStream(fileInputStream, cipher);
  byte[] fileByte = new byte[(int) file.length()];
  int j = cipherInputStream.read(fileByte);
  return fileByte;
  </code></pre>
  
  <p>cipher and key were generated before and are used in whole app:</p>
  
  <pre><code> key = new SecretKeySpec(keyValue, "AES");
   try {
       cipher = Cipher.getInstance("AES");
   } catch (Exception e) {
       e.printStackTrace();
   }
  </code></pre>
  
  <p>When I decrypt a file with about 200,000 bytes in android 5.0, j (variable before return) is about 8000 which is much lower than 200000, while in older android versions it is exactly equal to decrypted file length.</p>
  
  <p>I found that the problem is in decryption. Because I can encrypt a file in android 5.0 and decrypt it in older android versions, but not vice versa. However I am posting encryption process:</p>
  
  <pre><code>cipher.init(Cipher.ENCRYPT_MODE, AESutil.key);
  cipherOutputStream = new CipherOutputStream(output, cipher);
  byte data[] = new byte[1024];
  int count;
  while ((count = input.read(data)) != -1) {
      cipherOutputStream.write(data, 0, count);
  }
  </code></pre>
  
  <p>Thanks in advance</p>