Zig
Zig
Verify a Zip's Password
See more Zip Examples
Demonstrates how to verify the password for an encrypted or password-protected zip archive.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const zip = try chilkat.Zip.init();
defer zip.deinit();
// To verify a password for a Zip, the Zip must be opened:
zip.openZip("myProtected.zip") catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// Set the password to be verified:
zip.setDecryptPassword("secret");
const password_ok = zip.verifyPassword();
if (password_ok) {
std.debug.print("Password is correct.\n", .{});
} else {
std.debug.print("Password is incorrect.\n", .{});
}
zip.closeZip();
}