(Swift) Create Password Protected Zip containing a Single File.
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.) Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let zip = CkoZip()!
success = zip.newZip("test.zip")
if success == false {
print("\(zip.lastErrorText!)")
return
}
zip.setPassword("secret")
zip.passwordProtect = true
var saveExtraPath: Bool
saveExtraPath = false
success = zip.addFile("/temp/hamlet.xml", saveExtraPath: saveExtraPath)
success = zip.writeAndClose()
if success == false {
print("\(zip.lastErrorText!)")
return
}
print("Zip Created!")
}
|