My goal here is to decrypt an entire file into another file.
This output loop for some reason will not write to addmsgOut if the cypherBufStream (a BufferedInputStream reading an input file) is too small i.e. around 128 bytes. When bringing in larger files 38kb and up it works fine. I keep banging my head against the wall trying to figure it out and would love some help.
// 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();
}