当使用bouncy castle作为加密提供程序和GCM时,cipherOutputStream.close()似乎不会抛出invalidCipherTextException

时间:2013-05-17 16:05:10

标签: java bouncycastle

当使用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()或者我误解了什么?

0 个答案:

没有答案