当使用Bouncy Castle作为提供者和GCM时,如果我故意修改了密文,则应该抛出invalidCipherTextException,如果我在cipherOutputStream.close()上调试模式,我可以看到invalidCipherTextException但是我无法捕获这个异常
BufferedInputStream is = new BufferedInputStream(new FileInputStream(user.encryptedDirectory.containedFiles.get(counter)));
CipherOutputStream os = new CipherOutputStream(new FileOutputStream(user.unencryptedDirectory.location.toAbsolutePath() + "\\"+ user.encryptedDirectory.containedFiles.get(counter).getName() + ""), cipher);
copy(is,os);
is.close();
os.close();
private static void copy(InputStream is, OutputStream os) throws IOException {
int i;
byte[] b = new byte[1024];
while((i=is.read(b))!=-1) {
os.write(b, 0, i);
}
}
我是否需要重写以便调用cipher.doFinal()或者我误解了什么?