Sample code for 30+ languages & platforms
Java

Verify a Zip's Password

See more Zip Examples

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

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Zip;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Zip zip = new Zip();

        // To verify a password for a Zip, the Zip must be opened:
        try {
            zip.openZip("myProtected.zip");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Set the password to be verified:
        zip.setDecryptPassword("secret");

        boolean passwordOk = zip.verifyPassword();
        if (passwordOk) {
            System.out.println("Password is correct.");
        } else {
            System.out.println("Password is incorrect.");
        }

        zip.closeZip();
    }
}