· 8 years ago · Feb 01, 2018, 07:48 PM
1static void fileProcessor(int cipherMode, String key, File inputFile, File
2 outputFile){
3
4 try {
5 Key secretKey = new SecretKeySpec(key.getBytes(), "AES");
6 Cipher cipher = Cipher.getInstance("AES");
7 cipher.init(cipherMode, secretKey);
8 FileInputStream inputStream = new FileInputStream(inputFile);
9
10 byte[] inputBytes = new byte[(int) inputFile.length()];
11 inputStream.read(inputBytes);
12 byte[] outputBytes = cipher.doFinal(inputBytes);
13
14 FileOutputStream outputStream = new FileOutputStream(outputFile);
15 outputStream.write(outputBytes);
16 inputStream.close();
17 outputStream.close();
18
19
20 } catch (NoSuchPaddingException | NoSuchAlgorithmException
21 | InvalidKeyException | BadPaddingException
22 | IllegalBlockSizeException | IOException e){
23 Log.i("aes", "fileProcessor: " + e.getMessage());
24 }
25}