Skip to content

Commit 5fdaccc

Browse files
superandrew213plrthink
authored andcommitted
feat(ios): add AES encryption support for zipFolderWithPassword
- Use SSZipArchive's AES-enabled method for folder zipping - Import zlib.h for compression level constants - Improve error messages in unzipWithPassword to show actual error - Update README to reflect iOS AES encryption support Note: zipFilesWithPassword still uses standard encryption as SSZipArchive doesn't expose an AES variant for file array zipping.
1 parent ea67eb0 commit 5fdaccc

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ zip(sourcePath, targetPath)
8181
8282
***NOTE: the string version of source is for folder, the string[] version is for file, so if you want to zip a single file, use zip([file]) instead of zip(file)***
8383

84-
***NOTE: encryptionType is not supported on iOS yet, so it would be igonred on that platform.***
84+
***NOTE: On iOS, AES-256 and AES-128 both use AES-256 encryption.***
8585

8686
Example
8787

ios/RNZipArchive.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "RNZipArchive.h"
10+
#import <zlib.h>
1011

1112
#if __has_include(<React/RCTEventDispatcher.h>)
1213
#import <React/RCTEventDispatcher.h>
@@ -91,7 +92,8 @@ -(void)stopObserving {
9192
if (success) {
9293
resolve(destinationPath);
9394
} else {
94-
reject(@"unzip_error", @"unable to unzip", error);
95+
NSString *errorMessage = error ? [error localizedDescription] : @"unable to unzip";
96+
reject(@"unzip_error", errorMessage, error);
9597
}
9698
}
9799

@@ -156,7 +158,8 @@ -(void)stopObserving {
156158

157159
BOOL success;
158160
[self setProgressHandler];
159-
success = [SSZipArchive createZipFileAtPath:destinationPath withContentsOfDirectory:from keepParentDirectory:NO withPassword:password andProgressHandler:self.progressHandler];
161+
BOOL useAES = encryptionType && ![encryptionType isEqualToString:@"STANDARD"];
162+
success = [SSZipArchive createZipFileAtPath:destinationPath withContentsOfDirectory:from keepParentDirectory:NO compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:useAES progressHandler:self.progressHandler];
160163

161164
self.progress = 1.0;
162165
[self zipArchiveProgressEvent:1 total:1]; // force 100%
@@ -181,6 +184,7 @@ -(void)stopObserving {
181184

182185
BOOL success;
183186
[self setProgressHandler];
187+
// Note: withFilesAtPaths doesn't have AES class method, using password only
184188
success = [SSZipArchive createZipFileAtPath:destinationPath withFilesAtPaths:from withPassword:password];
185189

186190
self.progress = 1.0;

0 commit comments

Comments
 (0)