Sample code for 30+ languages & platforms
AutoIt

Encrypt Already Existing Zip

See more Zip Examples

To encrypt an already existing non-encrypted .zip, the application must open the .zip, set the encryption related properties, and then re-write.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This requires the Chilkat Zip API to have been previously unlocked.
; See Unlock Chilkat Zip for sample code.

$oZip = ObjCreate("Chilkat.Zip")

; Open an unencrypted .zip
$bSuccess = $oZip.OpenZip("qa_data/zips/test.zip")
If ($bSuccess <> True) Then
    ConsoleWrite($oZip.LastErrorText & @CRLF)
    Exit
EndIf

; Unzip to a temp directory.
Local $iNumFilesUnzipped = $oZip.Unzip("qa_output/tmp")
If ($iNumFilesUnzipped < 0) Then
    ConsoleWrite($oZip.LastErrorText & @CRLF)
    Exit
EndIf

; Clear the zip object.
$oZip.NewZip("qa_output/aesTest.zip")

; Indicate that 128-bit AES encryption is to be used when writing the .zip
$oZip.Encryption = 4
$oZip.EncryptKeyLength = 128

; Set the password.
$oZip.EncryptPassword = "secret"

; Append the files.
$oZip.AppendFromDir = "qa_output/tmp"
$bSuccess = $oZip.AppendFiles("*.*",True)
If ($bSuccess <> True) Then
    ConsoleWrite($oZip.LastErrorText & @CRLF)
    Exit
EndIf

; Write the .zip and close it.
$bSuccess = $oZip.WriteZipAndClose()
If ($bSuccess <> True) Then
    ConsoleWrite($oZip.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Success." & @CRLF)