如何加密java 7z存档?
我正在使用ApacheCommonsCompress来压缩文件。 如何将密码添加到存档中如何加密java 7z存档?,java,password-encryption,apache-commons-compress,Java,Password Encryption,Apache Commons Compress,我正在使用ApacheCommonsCompress来压缩文件。 如何将密码添加到存档中 public static void main(String args[]) throws FileNotFoundException, IOException { SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("outFile.7z")); File entryFile = new File("D:/image.jpg"); S
public static void main(String args[]) throws FileNotFoundException, IOException {
SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("outFile.7z"));
File entryFile = new File("D:/image.jpg");
SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(entryFile, entryFile.getName());
sevenZOutput.putArchiveEntry(entry);
FileInputStream in = new FileInputStream(entryFile);
int len;
byte buffer[] = new byte[8192];
int transferedMegaBytes2=0;
while ((len = in.read(buffer)) > 0) {
sevenZOutput.write(buffer, 0, len);
transferredBytes += len;
int transferedMegaBytes = (int) (transferredBytes / 1048576);
if(transferedMegaBytes>transferedMegaBytes2){
System.out.println("Transferred: " + transferedMegaBytes + " Megabytes.");
transferedMegaBytes2=transferedMegaBytes;
}
}
sevenZOutput.closeArchiveEntry();
sevenZOutput.close();
}
我认为你不能使用Commons压缩。从Apache Commons压缩站点的部分: 我们目前只提供lzma、arj、dump和Z.arj的读取支持 只能读取未压缩的归档文件,7z可以读取具有多个 7z支持压缩和加密算法,但不支持 写入归档文件时支持加密
恐怕不支持压缩。你可能想用这个
如果这样做,您可能会失去平台独立性。(他们说这是跨平台的,但我不敢打赌)你们有其他的图书馆让我使用吗?我想用lzma压缩。也许7zip lzma SDK可以做到,但我还没有尝试过,而且文档似乎有点缺乏。与其试图保护存档本身,为什么不通过某种类型的加密流来运行输出流,以便对内容进行加密,然后进行压缩。。。?