Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Rust Downloads

Rust

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

let zip = chilkat::Zip::new();

if zip.new_zip("test.zip").is_err() {
    println!("{}", zip.last_error_text());
    return;
}

zip.set_password("secret");
zip.set_password_protect(true);

let save_extra_path = false;
let _ = zip.add_file("/temp/hamlet.xml", save_extra_path).is_ok();

if zip.write_zip_and_close().is_err() {
    println!("{}", zip.last_error_text());
    return;
}

println!("Zip Created!");