아카이브 보호 아카이브

ASPOSE.zip API를 사용하면 기본 파일 구조에 대해 걱정하지 않고 Java에서 파일을 압축하고 압축 할 수 있습니다. 이 기사에서는 단일 및 여러 파일 압축 작업을 보여줍니다.

아카이브 압축

전통적인 암호화 체계로 파일 암호화

1try (fileoutputStream ZipFile =  FileOutputStream (datAdir + "compressWithTraditionAlenCryption_out.zip")) {
2    try (fileInputStream source1 = new FileInputStream (datAdir + "alice29.txt")) {
3        Archive Archive = New Archive (New ArchiveEntrySettings (NULL, NEW NEW TRAISTIVENCENDRYPTIONSETTINGS ( "P@S $"));
4        archive.createentry ( "alice29.txt", source1);
5        Archive.save (zipfile);
6    }
7} catch (ioException ex) {
8    System.out.println (예);
9}

AES 암호화로 파일 암호화

AES128을 가진 파일 암호화

1try (fileoutputStream ZipFile =  FileOutputStream (DatAdir + "PasswordProtectWitHaes128_out.zip")) {
2    try (fileInputStream source1 = new FileInputStream (datAdir + "alice29.txt")) {
3        Archive Archive = New Archive (New ArchiveEntrySettings (NULL, NEW AESENCRYPTIONSETTINGS ( "P@S $", EncryptionMethod.aes128)));
4        archive.createentry ( "alice29.txt", source1);
5        Archive.save (zipfile);
6    }
7} catch (ioException ex) {
8    System.out.println (예);
9}

AES192로 파일 암호화

1try (fileoutputStream ZipFile =  FileOutputStream (DatAdir + "PasswordProtectWitHaes192_out.zip")) {
2    try (fileInputStream source1 = new FileInputStream (datAdir + "alice29.txt")) {
3        Archive Archive = New Archive (New ArchiveEntrySettings (NULL, NEW AESENCRYPTIONSETTINGS ( "P@S $", EncryptionMethod.aes192)));
4        archive.createentry ( "alice29.txt", source1);
5        Archive.save (zipfile);
6    }
7} catch (ioException ex) {
8    System.out.println (예);
9}

AES256이있는 파일 암호화

1try (fileoutputStream ZipFile =  FileOutputStream (datAdir + "passwordProtectWitHaes256_out.zip")) {
2    try (fileInputStream source1 = new FileInputStream (datAdir + "alice29.txt")) {
3        Archive Archive = New Archive (New ArchiveEntrySettings (NULL, NEW AESENCRYPTIONSETTINGS ( "P@S $", EncryptionMethod.aes256)));
4        archive.createentry ( "alice29.txt", source1);
5        Archive.save (zipfile);
6    }
7} catch (ioException ex) {
8    System.out.println (예);
9}

비밀번호 보호 디렉토리

1try (fileoutputStream ZipFile =  FileOutputStream ( ". \\ all_corpus_encrypted_out.zip")) {
2    파일 코퍼스 =  파일 ( ". \\ CanterburyCorpus");
3    Try (Archive Archive = New Archive (New ArchiveEntrySettings (NULL, NEW NEWELTENDENCRYPTIONSETTINGS ( "P@S $"))) {
4        Archive.createentries (코퍼스);
5        Archive.save (zipfile);
6    }
7} catch (ioException ex) {
8    System.out.println (예);
9}

혼합 암호화 기술로 여러 파일을 암호화

 1try (fileoutputStream ZipFile =  FileOutputStream ( "archive.zip")) {
 2    파일 fi1 =  파일 ( "data1.bin");
 3    파일 fi2 =  파일 ( "data2.bin");
 4    파일 fi3 =  파일 ( "data3.bin");
 5    try (Archive Archive = new Archive ()) {
 6        Archive.CreateEntry ( "Entry1.bin", Fi1, False, New ArchiveEntrySettings (New deflateCompressionSettings (), 새로운 전통적인 enccryptionsettings ( "pass1"));
 7        Archive.CreateEntry ( "eTryT.Bin", Fi2, False, New ArchiveEntrySettings (New deflateCompressionSettings (), New Aesencryptionsettings ( "Pass2", EncryptionMethod.aes128));
 8        Archive.CreateEntry ( "eTryTe3.bin", Fi3, False, New ArchiveEntrySettings (New deflateCompressionSettings (), New Aesencryptionsettings ( "Pass3", EncryptionMethod.aes256));
 9        Archive.save (zipfile);
10    }
11} catch (ioexception 무시) {
12}

감압 아카이브

전통적으로 암호 보호 된 아카이브의 압축 해제

 1try (fileInputStream fs = new FileInputStream (datAdir + "compressWithTraditionAlenCryption_in.zip")) {
 2    try (fileoutputStream 추출 =  FileOutputStream (datAdir + "alice_extracted_out.txt")) {
 3        archiveloadoptions 옵션 = 새로운 archiveloadoptions ();
 4        옵션 .setDecryptionPassword ( "p@s $");
 5        try (아카이브 아카이브 = 새로운 아카이브 (fs, 옵션)) {
 6            try (inputstream defompressed = archive.getentries (). get (0) .open ()) {
 7                바이트 [] B = 새로운 바이트 [8192];
 8                int bytesread;
 9                while (0 <(bytesread = decompressed.read (b, 0, b.length))) {
10                    extracted.write (b, 0, 바이트 스레드);
11                }
12            }
13        }
14    }
15} catch (ioException ex) {
16    System.out.println (예);
17}

압축 압력 AES 암호화 아카이브

 1try (fileInputStream fs = new FileInputStream (datAdir + "passwordProtectWitHaes256_in.zip")) {
 2    try (fileoutputStream 추출 =  FileOutputStream (datAdir + "alice_aesextracted_out.txt")) {
 3        try (아카이브 아카이브 = 새로운 아카이브 (fs)) {
 4            try (inputstream defompressed = archive.getentries (). get (0) .open ( "p@s $")) {
 5                바이트 [] B = 새로운 바이트 [8192];
 6                int bytesread;
 7                while (0 <(bytesread = decompressed.read (b, 0, b.length))) {
 8                    extracted.write (b, 0, 바이트 스레드);
 9                }
10            }
11        }
12    }
13} catch (ioException ex) {
14    System.out.println (예);
15}

압축 압축 AES 인 암호화 된 저장된 아카이브

 1try (fileInputStream fs = new FileInputStream (datAdir + "storeMutlipleFileswithOutcopressionwithPassword_in.zip")) {
 2    try (fileoutputStream 추출 =  FileOutputStream (datAdir + "alice_aesextracted_out.txt")) {
 3        archiveloadoptions 옵션 = 새로운 archiveloadoptions ();
 4        옵션 .setDecryptionPassword ( "p@s $");
 5        try (아카이브 아카이브 = 새로운 아카이브 (fs, 옵션)) {
 6            try (inputstream defompressed = archive.getentries (). get (0) .open ()) {
 7                바이트 [] B = 새로운 바이트 [8192];
 8                int bytesread;
 9                while (0 <(bytesread = decompressed.read (b, 0, b.length))) {
10                    extracted.write (b, 0, 바이트 스레드);
11                }
12            }
13        }
14    }
15} catch (ioException ex) {
16    System.out.println (예);
17}

암호화 된 폴더를 디렉토리로 압축 함

1try (fileInputStream ZipFile = new FileInputStream ( ". \\ all_corpus_encrypted.zip")) {
2    archiveloadoptions 옵션 = 새로운 archiveloadoptions ();
3    옵션 .setDecryptionPassword ( "p@s $");
4     아카이브 (zipfile, 옵션). ExtractTodirectory ( ". \\ all_corpus_decrypted");
5} catch (ioException ex) {
6    System.out.println (예);
7}

단일 파일을 갖는 아카이브를 압축 압력을 가하는 것

 1try (fileInputStream fs = new FileInputStream (datAdir + "compressedSingleFile.zip")) {
 2    try (아카이브 아카이브 = 새로운 아카이브 (fs)) {
 3        int [] % 준비 = new int [] {0};
 4        archive.getentries (). get (0) .setextractionProgressed (새 이벤트 <ProgroseEventArgs> () {
 5            @보수
 6            Public Void Invoke (Object Sender, ProgressEventArgs ProgressEventArgs) {
 7                int 백분율 = (int) ((100 * progressEventArgs.getProeceededBytes ()) / ((ArchiveEntry) sender) .getUncompressedSize ());
 8                if ( %> 퍼센트 준비 [0]) {
 9                    System.out.println (% + "% 압축 압축");
10                    퍼지 준비 [0] = %;
11                }
12            }
13        });
14        archive.getentries (). get (0) .extract (datadir + "alice_extracted_out.txt");
15    }
16} catch (ioException ex) {
17    System.out.println (예);
18}

여러 파일이있는 아카이브를 압축 압력을 가하는 것

 1try (fileInputStream fs = new FileInputStream (datAdir + "compressedMultipleFiles.zip")) {
 2    StringBuilder sb = new StringBuilder ( "항목은 :");
 3    int [] % 준비 = new int [] {0};
 4    archiveloadoptions 옵션 = 새로운 archiveloadoptions ();
 5    옵션.
 6        @보수
 7        public void invoke (Object Sender, EntryEventArgs EntryEventArgs) {
 8            sb.Append (elenteEventArgs.getEntry (). getName ()). Append ( ",");
 9        }
10    });
11    옵션.
12        @보수
13        Public Void Invoke (Object Sender, ProgressEventArgs ProgressEventArgs) {
14            int 백분율 = (int) ((100 * progressEventArgs.getProeceededBytes ()) / ((ArchiveEntry) sender) .getUncompressedSize ());
15            if ( %> 퍼센트 준비 [0]) {
16                System.out.println (% + "% 압축");
17                퍼지 준비 [0] = %;
18            }
19        }
20    });
21    try (아카이브 아카이브 = 새로운 아카이브 (fs, 옵션)) {
22        System.out.println (sb.substring (0, sb.length () -2));
23        try (fileoutputStream 추출 =  FileOutputStream (datAdir + "alice_extracted_out.txt")) {
24            try (inputstream defompressed = archive.getentries (). get (0) .open ()) {
25                바이트 [] 버퍼 = 새로운 바이트 [8192];
26                int bytesread;
27                while (0 <(bytesread = decompressed.read (buffer, 0, buffer.length))) {
28                    extracted.write (Buffer, 0, BytesRead);
29                }
30                // 감압 된 스트림에서 파일 추출까지 읽습니다.
31            }
32        }
33        퍼지 준비 [0] = 0;
34        archive.getentries (). get (1) .extract (datadir + "asyoulik_extracted_out.txt");
35    }
36} catch (ioException ex) {
37    System.out.println (예);
38}

압축없이 저장된 아카이브 추출

 1try (fileInputStream ZipFile = new FileInputStream (DatAdir + "StoreMultipleFileswithOutCompression.zip"))) {
 2    시도 (아카이브 아카이브 =  아카이브 (zipfile)) {
 3        try (fileoutputStream 추출 =  FileOutputStream (datAdir + "alice_extracted_store_out.txt")) {
 4            try (inputstream defompressed = archive.getentries (). get (0) .open ()) {
 5                바이트 [] 버퍼 = 새로운 바이트 [8192];
 6                int bytesread;
 7                while (0 <(bytesread = decompressed.read (buffer, 0, buffer.length))) {
 8                    extracted.write (Buffer, 0, BytesRead);
 9                }
10                // 감압 된 스트림에서 파일 추출까지 읽습니다.
11            }
12        }
13        try (fileoutputStream 추출 =  FileOutputStream (datAdir + "asyoulik_extracted_store_out.txt")) {
14            try (inputstream defompressed = archive.getentries (). get (1) .open ()) {
15                바이트 [] 버퍼 = 새로운 바이트 [8192];
16                int bytesread;
17                while (0 <(bytesread = decompressed.read (buffer, 0, buffer.length))) {
18                    extracted.write (Buffer, 0, BytesRead);
19                }
20                // 감압 된 스트림에서 파일 추출까지 읽습니다.
21            }
22        }
23    }
24} catch (ioException ex) {
25    System.out.println (예);
26}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.