[英]zip4j: Does getting the Stream from encrypted file creates a temporary unencrypted staging area?
我有以下代码在Android上使用zip4j读取加密的zip文件。 我不提供临时文件。 zip4j是否会创建用于解密的临时文件? 或者zip标准是否允许即时解密,因此没有加密数据临时写入存储?
ZipFile table = null;
try {
table = new ZipFile("/sdcard/file.zip");
if( table.isEncrypted() ){
table.setPassword("password");
}
} catch (Exception e) {
// if can't be opened then return null
e.printStackTrace();
return;
}
InputStream in = null;
try {
FileHeader entry = table.getFileHeader("file.txt");
in = table.getInputStream(entry);
...
作为Zip4j的作者,我可以保证Zip4j不会创建任何临时文件进行解密。
Zip4j将解密内存中的数据,并且不会将加密数据写入任何临时文件。 Zip格式规范允许AES和标准Zip加密的动态或内存中解密。
这是来自zip4j源
public ZipInputStream getInputStream() throws ZipException {
if (fileHeader == null) {
throw new ZipException("file header is null, cannot get inputstream");
}
RandomAccessFile raf = null;
try {
raf = createFileHandler(InternalZipConstants.READ_MODE);
String errMsg = "local header and file header do not match";
//checkSplitFile();
if (!checkLocalHeader())
throw new ZipException(errMsg);
init(raf);
...
}
private RandomAccessFile createFileHandler(String mode) throws ZipException {
if (this.zipModel == null || !Zip4jUtil.isStringNotNullAndNotEmpty(this.zipModel.getZipFile())) {
throw new ZipException("input parameter is null in getFilePointer");
}
try {
RandomAccessFile raf = null;
if (zipModel.isSplitArchive()) {
raf = checkSplitFile();
} else {
raf = new RandomAccessFile(new File(this.zipModel.getZipFile()), mode);
}
return raf;
} catch (FileNotFoundException e) {
throw new ZipException(e);
} catch (Exception e) {
throw new ZipException(e);
}
}
我相信raf = new RandomAccessFile(new File(this.zipModel.getZipFile()), mode);
line表示它确实在加密的zip文件的路径的子目录下创建解密文件。
我不知道你是否可以动态解压缩(可能不是)。 如果您不希望人们查看解密文件,请考虑将zip文件存储在应用程序受保护的内部存储空间而不是SD卡中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.