Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
7Zip在JAVA中的实现_Java_Aes_7zip - Fatal编程技术网

7Zip在JAVA中的实现

7Zip在JAVA中的实现,java,aes,7zip,Java,Aes,7zip,我从7zip网站下载了LZMA SDK,但令我失望的是,它只支持压缩和解压缩,不支持AES加密。是否有人知道是否有完全在JAVA中使用AES加密的7zip实现?。谢谢 问候,, 卡尔。根据7Zip团队: LZMA SDK不支持加密 方法。使用7-Zip源代码 相反

我从7zip网站下载了LZMA SDK,但令我失望的是,它只支持压缩和解压缩,不支持AES加密。是否有人知道是否有完全在JAVA中使用AES加密的7zip实现?。谢谢

问候,, 卡尔。

根据7Zip团队:

LZMA SDK不支持加密 方法。使用7-Zip源代码 相反


<源代码可在汇编程序、C语言和C++语言中使用,可以从java调用它们。 请注意,Commons Compress目前仅支持用于7z归档的压缩和加密算法的子集。对于仅写入未压缩的条目,支持LZMA、LZMA2、BZIP2和Deflate,此外,还支持读取AES-256/SHA-256和DEFLATE64

如果您使用公共压缩,您的代码的可移植性可能不会有问题,因为您不必嵌入任何本机库

下面的代码显示了如何迭代7zip存档中的文件并将其内容打印到标准输出。您可以根据AES要求对其进行调整:

public static void showContent(String archiveFilename) throws IOException {

    if (archiveFilename == null) {
        return;
    }

    try (SevenZFile sevenZFile = new SevenZFile(new File(archiveFilename))) {
        SevenZArchiveEntry entry = sevenZFile.getNextEntry();
        while (entry != null) {
                final byte[] contents = new byte[(int) entry.getSize()];
                int off = 0;
                while ((off < contents.length)) {
                    final int bytesRead = sevenZFile.read(contents, off, contents.length - off);
                    off += bytesRead;
                }
                System.out.println(new String(contents, "UTF-8"));              
            entry = sevenZFile.getNextEntry();
        }
    }
}
使用的Maven依赖项:

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-compress</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>org.tukaani</groupId>
        <artifactId>xz</artifactId>
        <version>1.6</version>
    </dependency>

org.apache.commons
公用压缩
1.18
org.tukaani
xz
1.6

请注意:org.tukaani:xz仅适用于7zip。对于其他受支持的压缩格式,common compress依赖项不需要它。

来源:因为我一直在寻找它,让我澄清一下:Commons compress不支持编写加密的7z文件。
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-compress</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>org.tukaani</groupId>
        <artifactId>xz</artifactId>
        <version>1.6</version>
    </dependency>