title: Android Java decryption - saving the decrypted file
body: <p>So I'm working on an application where I need to decrypt encrypted files.The encryption is done with PHP and decryption with Java.I've tested,there is no problem with the encryption/decryption in Java program.But my problem is that I can't run the same application in Android.I need to find away how to get the encrypted data.For now i prefer to store it in assets folder manually, just for tests and get it like this : </p>
  
  <pre><code>AssetManager am = this.getAssets();
  InputStream is = am.open("AUDIOVISUALFOTO02.pdf"); //or image file
  </code></pre>
  
  <p>After that I need to save the decrypted file somewhere so I can see if decryption is working on the device too.So basically I need to find a way how to get the encrypted file from assets folder as example and where to store the decrypted file (dowsn't matter where).Here is the code that I'm using for decryption :</p>
  
  <pre><code>package com.android.decrypt;
  
  import java.io.*;
  import javax.crypto.*;
  import javax.crypto.spec.*;
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  
      public class DecryptPDFActivity extends Activity {
  
          @Override
          public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          try {
  
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          SecretKeySpec keySpec = new SecretKeySpec("01234567890abcde".getBytes(), "AES");
          IvParameterSpec ivSpec = new IvParameterSpec("fedcba9876543210".getBytes());
          cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
  
          //FileInputStream fis   = new FileInputStream(new File("encrypted.pdf"));
          CipherInputStream cis = new CipherInputStream(fis, cipher);
          FileOutputStream fos  = new FileOutputStream(new File("decrypted.pdf"));
  
          byte[] b = new byte[8];
          int i;
  
          while ((i = cis.read(b)) != -1) {
            fos.write(b, 0, i);
          }
          fos.flush(); fos.close();
          cis.close(); fis.close();
  
          }
          catch(Exception e)
          {
              e.fillInStackTrace();
              Log.e("Error", "Damned ! : "+e);
          }
        }
  }
  </code></pre>
  
  <p>So any help or suggestions how to do this are welcomed.</p>