Unlock ZIP password

Forgotten password

It is common to forget password “partly”, i. e. remember some characters of it while forgetting others. Aspose.ZIP API lets you play with such half-forgotten passwords to unlock the archive. This article shows guessing the decryption password of the AES-encrypted zip archive.

Identifying password template

Let’s say your password starts with “T0p$ecret” symbols followed by capital English letter and two digits. So, we can describe a template like this:

1String template = "T0p$ecret{0}{1}";
where former placeholder is for capital english letter, latter is for two-digit number.

Verifying single password

This simple decryption code

1ArchiveLoadOptions options = new ArchiveLoadOptions();
2options.setDecryptionPassword(password);
3try (Archive a = new Archive("encrypted.zip", options))
4    a.extractToDirectory(".");
raises an InvalidDataException if wrong password has been supplied.

Brute force attack on the archive

So compose and test passwords one by one. If there will be success program prints the proper password to the console.

 1String template = "T0p$ecret{0}{1}";
 2for (char c = 'A'; c < 'Z'; c++)
 3{
 4    boolean correct = false;
 5    for (int i = 10; i < 99; i++)
 6    {
 7        String password = MessageFormat.format(template, c, i);
 8        ArchiveLoadOptions options = new ArchiveLoadOptions();
 9        options.setDecryptionPassword(password);
10        try (Archive a = new Archive("encrypted.zip", options)) {
11            a.extractToDirectory(".");
12            correct = true;
13        }
14        catch (InvalidDataException e)
15        {
16            correct = false;
17        }
18
19        if (correct)
20        {
21            System.out.println("Proper password: " + password);
22            break;
23        }
24    }
25
26    if (correct)
27        break;
28}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.