문서의 암호화 및 해독을 수행합니다. 처음에는 바이트 배열로 파일을 읽고 바이트 배열을 암호화 된 메서드에 전달했습니다. 최대 50MB 크기까지, 나는 문제없이 파일을 암호화 할 수있다. 하지만 내가 파일 크기를 80MB로 늘리면 memoryException을 나타내는 cipher.doFinal()이 faling됩니다. 큰 파일을 아무런 문제없이 암호화하는 방법? 또한 doFinal() 메소드는 크기 제한이 있습니다. 저에게 알려주세요. 이 내 코드입니다 :decipher.doFinal (file_encrypt)로 해독하는 방법
공공 문자열 해독 (바이트 [] file_encrypt) 예외 {
String key22 = myKey;
byte[] b = key22.getBytes();
final SecretKey key = new SecretKeySpec(b, "DESede");
final IvParameterSpec iv = new IvParameterSpec(new byte[8]);
final Cipher decipher = Cipher.getInstance("DESede/CBC/NoPadding");
decipher.init(Cipher.DECRYPT_MODE, key, iv);
final byte[] plainText = decipher.doFinal(file_encrypt);
try {
String dir = Environment.getExternalStorageDirectory() + File.separator + ".android";
String dir2 = Environment.getExternalStorageDirectory() + File.separator + ".android/.androidmain";
File folder = new File(dir); //folder name
File folder2 = new File(dir2); //folder name
if (!folder.exists())
folder.mkdirs();
if (!folder2.exists())
folder2.mkdirs();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + ".android/.androidmain/file");
if (file.exists()) {
// Toast.makeText(contInst, "111", Toast.LENGTH_SHORT).show();
} else {
// Toast.makeText(contInst, "3333", Toast.LENGTH_SHORT).show();
file.createNewFile();
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bos.write(plainText);
bos.flush();
bos.close();
videoplay.setSource(Uri.fromFile(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return "ok";
}
예 바이트 배열을 청크 청크에 넣고 시도해 봐야하지만 작동하지 않아야합니다. – golbahar