/** * Sets the password for the zip file.<br> * <b>Note</b>: For security reasons, usage of this method is discouraged. Use * setPassword(char[]) instead. As strings are immutable, they cannot be wiped * out from memory explicitly after usage. Therefore, usage of Strings to store * passwords is discouraged. More info here: * http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx * @param password * @throws ZipException */ public void setPassword(String password) throws ZipException { if (!Zip4jUtil.isStringNotNullAndNotEmpty(password)) { throw new NullPointerException(); } setPassword(password.toCharArray()); }
/** * Sets the password for the zip file.<br> * <b>Note</b>: For security reasons, usage of this method is discouraged. Use * setPassword(char[]) instead. As strings are immutable, they cannot be wiped * out from memory explicitly after usage. Therefore, usage of Strings to store * passwords is discouraged. More info here: * http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx * @param password * @throws ZipException */ public void setPassword(String password) throws ZipException { if (!Zip4jUtil.isStringNotNullAndNotEmpty(password)) { throw new NullPointerException(); } setPassword(password.toCharArray()); }
@Override public ZipFileResource setPassword(char[] password) { try { getZipFile().setPassword(password); } catch (ZipException e) { throw new ResourceException("Error while setting the zip password", e); } return this; }
/** * Extract. * * @param zipFile4j * the zip file4j * @param destination * the destination * @param password * the password * @throws ZipException * the zip exception */ public static void extract(final ZipFile zipFile4j, final File destination, final String password) throws ZipException { if (zipFile4j.isEncrypted()) { zipFile4j.setPassword(password); } zipFile4j.extractAll(destination.getAbsolutePath()); }
throw new ZipException("Password can't be empty with encryption mode"); zFile.setPassword(password.toCharArray());
throw new ZipException("Password can't be empty with encryption mode"); zFile.setPassword(password.toCharArray());
public boolean restore(String password) { if(!isValid()) throw new IllegalStateException("Invalid backup file"); synchronized(Database.LOCK_DATA) { try { if(password != null) mZip.setPassword(password); mZip.extractAll(RxDroid.getPackageInfo().applicationInfo.dataDir); } catch(ZipException e) { final String msg = e.getMessage(); if(password != null && msg.toLowerCase(Locale.US).contains("password")) return false; throw new WrappedCheckedException(e); } Settings.init(true); } NotificationReceiver.rescheduleAlarmsAndUpdateNotification(false); return true; } }
/** * Decompress. * * @param sourceZipFilePath * the source zip file path * @param extractedZipFilePath * the extracted zip file path * @param password * the password */ public void decompress(String sourceZipFilePath, String extractedZipFilePath, String password) { try { ZipFile zipFile = new ZipFile(sourceZipFilePath); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } zipFile.extractAll(extractedZipFilePath); } catch (Exception e) { JKExceptionUtil.handle(e); } }
zipFile.setPassword(password);