したがって、32ビットコンピューターで復号化する必要があるこれらの大きなファイル(6GB +)があります。以前に使用した一般的な手順は、メモリ内のファイル全体を読み取り、それを復号化関数に渡してから、すべてをファイルに書き戻すというものでした。メモリの制限により、これは実際には機能しません。ファイルを部分的に復号化関数に渡そうとしましたが、復号化関数に送信する前にファイルを分割する場所の境界を台無しにしているようです。
キーサイズに応じてファイルを分割しようとしましたが、それは問題ではないようです。サイズ 2048 のバイト配列とサイズ 294 のバイト配列を試してみましたが、これは特別な境界であると考えていましたが、うまくいきませんでした。ファイルの一部は正しく復号化されていますが、完全に意味不明な部分があります。
ファイルをチャンクで復号化することは不可能ですか? 方法があるとすれば、どのように?
これが私の復号化機能です/部分的に復号化する私の試みです。
private Path outFile;
private void decryptFile(FileInputStream fis, byte[] initVector, byte[] aesKey, long used) {
//Assume used = 0 for this function.
byte[] chunks = new byte[2048]; //If this number is greater than or equal to the size of the file then we are good.
try {
if (outFile.toFile().exists())
outFile.toFile().delete();
outFile.toFile().createNewFile();
FileOutputStream fos = new FileOutputStream(outFile.toFile());
OutputStreamWriter out = new OutputStreamWriter(fos);
IvParameterSpec spec = new IvParameterSpec(Arrays.copyOfRange(initVector, 0, 16));
SecretKeySpec key = new SecretKeySpec(aesKey, "AES");
Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, key, spec);
int x;
while ((x = fis.read(chunks, 0, chunks.length)) != -1) {
byte[] dec = cipher.doFinal(Arrays.copyOfRange(chunks, 0, x));
out.append(new String(dec));
}
out.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
LOG.error(ExceptionUtils.getStackTrace(e));
}
}