I am trying to encrypt a 23 MB file using AES algorithm in Android. While the code works when the file size is around 3-4 MB. But when I tested with a 23 MB file it gives me a java.lang.OutOfMemoryError
Here is the code-
                 try{
                        SecretKeySpec skey = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
                        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
                        cipher.init(Cipher.ENCRYPT_MODE, skey);
                        output = cipher.doFinal(bFile);
                        String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
                        FileOutputStream fileOuputStream = new FileOutputStream(SD_CARD_PATH+ "/" + "abcd.db"); 
                        fileOuputStream.write(output);
                        fileOuputStream.close();
                        //System.out.println(output);
                    }catch(Exception e){
                        System.out.println("Error: "+e);
                    }
I get this error in the line- output = cipher.doFinal(bFile); 
Is there any other way to do this? What should I do?
 
     
     
    