我的目标是将整个文件解密为另一个文件。
如果 cypherBufStream(读取输入文件的 BufferedInputStream)太小,即大约 128 字节,则此输出循环出于某种原因不会写入 addmsgOut。当引入 38kb 及以上的较大文件时,它工作正常。我一直把头撞在墙上试图弄清楚,并希望得到一些帮助。
// Decrypt M and H using RSA encryption
OutputStream addmsgOut = new BufferedOutputStream(new FileOutputStream("message.add-msg"));
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] piece = new byte[128];
int e;
ByteArrayOutputStream out4 = new ByteArrayOutputStream();
while ((e = cypherBufStream.read(piece)) != -1) {
out4.write(piece, 0, e);
addmsgOut.write(cipher.doFinal(out4.toByteArray()));
out4.reset();
}