Skip to content

Instantly share code, notes, and snippets.

@mightyfrog
Last active March 21, 2017 20:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightyfrog/3c94b9c13e9f16ba3552 to your computer and use it in GitHub Desktop.
Save mightyfrog/3c94b9c13e9f16ba3552 to your computer and use it in GitHub Desktop.
winzipaes sample code

###winzipaes

how to zip

final String path = "/data/data/package-name/databases/my.db";
final File dbFile = new File(path);
final File file = new File(backupRoot, "db.zip");
AesZipFileEncrypter ze = null;
try {
    final AESEncrypter aesEncrypter = new AESEncrypterBC();
    ze = new AesZipFileEncrypter(file, aesEncrypter);
    ze.add(dbFile.getName(), new FileInputStream(dbFile), "password");
} catch (IOException e) {
    //
} finally {
    if (ze != null) {
        try {
            ze.close();
        } catch (IOException e) {
            // ignore
        }
    }
}

how to unzip

final String path = "/data/data/package-name/databases/my.db";
final File dbFile = new File(path);
final File file = new File(backupRoot, "db.zip");
AesZipFileDecrypter ze = null;
try {
    ze = new AesZipFileDecrypter(file, new AESDecrypterBC());
    ExtZipEntry entry = ze.getEntry(dbFile.getName());
    ze.extractEntry(entry, dbFile, "password");
} catch (DataFormatException | IOException e) {
    //
} finally {
    if (ze != null) {
        try {
            ze.close();
        } catch (IOException e) {
            // ignore
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment