Sample code for 30+ languages & platforms
Objective-C

Verify a Zip's Password

See more Zip Examples

Demonstrates how to verify the password for an encrypted or password-protected zip archive.

Chilkat Objective-C Downloads

Objective-C
#import <CkoZip.h>

BOOL success = NO;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoZip *zip = [[CkoZip alloc] init];

// To verify a password for a Zip, the Zip must be opened:
success = [zip OpenZip: @"myProtected.zip"];
if (success != YES) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

// Set the password to be verified:
zip.DecryptPassword = @"secret";

BOOL passwordOk;
passwordOk = [zip VerifyPassword];
if (passwordOk == YES) {
    NSLog(@"%@",@"Password is correct.");
}
else {
    NSLog(@"%@",@"Password is incorrect.");
}

[zip CloseZip];