您好,我无法中止密码操作。
在我的代码中,我加密了一个文件并将其读取到内存中,并且还检查了中止条件,该条件可能会停止加密。
想法是通过中止用户不再要求的操作来提高性能。
这是一个代码示例
try:
...
except:
pass
提前关闭流时,我得到Cihper cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.DECRYPT_MODE, someKey, someIV);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (InputStream in = new FileInputStream(someFile);
CipherOutputStream cipherStream = new CipherOutputStream(out, cipher)) {
int bytesRead;
byte[] buffer = new byte[16 * 1024];
while ((bytesRead = in.read(buffer)) > -1) {
if (checkAbortCondition()) { //should abort
return; //auto-closes the stream, this throws an exception!!
}
cipherStream.write(buffer, 0, bytesRead);
}
//more work...
} catch (Exception e) {
//exception handling
}
,这意味着流没有完成对文件中所有数据的加密。
堆栈跟踪位:
BadPaddingException
问:有没有办法关闭java.io.IOException: javax.crypto.BadPaddingException
2019-05-16 12:39:38.722 11145-11665/com.bubu.android W/System.err: at javax.crypto.CipherOutputStream.close(CipherOutputStream.java:214)
而不会引发异常?像“中止”之类的东西不会调用CipherOutputStream
?