我想要解密存储在我应用的res文件夹中的文件。此文件随应用程序一起分发,我在应用程序启动期间只尝试解密一次。
到目前为止,我已经找到了一些关于如何将解密文件写入SD卡的答案(this one, for instance),但是不知道该文件是否可以在SD卡上进行恶意访问?
我希望我可以将CipherInputStream
写入java.io.InputStream
,这样我就可以在不将任何解密数据写入磁盘的情况下使用它。有可能吗?
答案 0 :(得分:1)
我想你想要这样的东西
private InputStream getDecodedInputStream (InputStream eis) {
Cipher cipher = Cipher.getInstance("your cipher definition");
cipher.init(Cipher.DECRYPT_MODE, "your keySpec", new IvParameterSpec("your IV parameter spec"));
InputStream decryptedInputStream = new CipherInputStream(is, cipher);
return decryptedInputStream;
}
其中eis是您的加密输入流