/** * Add un-encrypted + un-zipped file to encrypted zip file.<br> * * @param file to add * @param pathForEntry to be used for addition of the file (path within zip file) * @param password to be used for encryption */ public void add(File file, String pathForEntry, String password) throws IOException, UnsupportedEncodingException { FileInputStream fis = new FileInputStream(file); try { add(pathForEntry, fis, password); } finally { fis.close(); } }
/** * Add un-encrypted + un-zipped file to encrypted zip file.<br> * * @param file to add * @param pathForEntry to be used for addition of the file (path within zip file) * @param password to be used for encryption */ public void add(File file, String pathForEntry, String password) throws IOException, UnsupportedEncodingException { FileInputStream fis = new FileInputStream(file); try { add(pathForEntry, fis, password); } finally { fis.close(); } }
@Override public <T> void writeEntities(String fileName, List<T> entities) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); this.objectMapper.writeValue(stream, entities); byte[] byteArray = stream.toByteArray(); this.encrypter.add(fileName, new ByteArrayInputStream(byteArray), this.password); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
/** * Add un-encrypted + un-zipped file to encrypted zip file. * * @param file to add, provides the path of the file within the zip file via its getPath() * @param password to be used for encryption */ public void add(File file, String password) throws IOException, UnsupportedEncodingException { FileInputStream fis = new FileInputStream(file); try { add(file.getPath(), fis, password); } finally { fis.close(); } }
/** * Add un-encrypted + un-zipped file to encrypted zip file. * * @param file to add, provides the path of the file within the zip file via its getPath() * @param password to be used for encryption */ public void add(File file, String password) throws IOException, UnsupportedEncodingException { FileInputStream fis = new FileInputStream(file); try { add(file.getPath(), fis, password); } finally { fis.close(); } }
/** * Take all elements (files) from zip file and add them ENCRYPTED with password to the new zip * file created with this instance. <br> * Encrypted data of each file has the same size as the compressed data, though the file size is * increased by 26 bytes for salt and pw-verification bytes.<br> * While the {@link #add(File, String)} method does not need an additional zip file, this method * comes in handy, when your input data is larger than your available memory. * * @param pathToZipFile * provides zipFileEntries for encryption * @param password * used to perform the encryption * @throws IOException */ public void addAll(File pathToZipFile, String password) throws IOException { ZipFile zipFile = new ZipFile(pathToZipFile); try { add(zipFile, password); } finally { zipFile.close(); } }
/** * Take all elements (files) from zip file and add them ENCRYPTED with password to the new zip * file created with this instance. <br> * Encrypted data of each file has the same size as the compressed data, though the file size is * increased by 26 bytes for salt and pw-verification bytes.<br> * While the {@link #add(File, String)} method does not need an additional zip file, this method * comes in handy, when your input data is larger than your available memory. * * @param pathToZipFile * provides zipFileEntries for encryption * @param password * used to perform the encryption * @throws IOException */ public void addAll(File pathToZipFile, String password) throws IOException { ZipFile zipFile = new ZipFile(pathToZipFile); try { add(zipFile, password); } finally { zipFile.close(); } }
protected void add(ZipFile inFile, String password) throws IOException, UnsupportedEncodingException { ZipFileEntryInputStream zfe = new ZipFileEntryInputStream(inFile.getName()); try { Enumeration<? extends ZipEntry> en = inFile.entries(); while (en.hasMoreElements()) { ZipEntry ze = en.nextElement(); zfe.nextEntry(ze); add(ze, zfe, password); } } finally { zfe.close(); } }
/** * Zip + encrypt one "inFile" to one "outZipFile" using "password". */ public static void zipAndEncrypt(File inFile, File outFile, String password, AESEncrypter encrypter) throws IOException { AesZipFileEncrypter enc = new AesZipFileEncrypter(outFile,encrypter); try { enc.add(inFile, password); } finally { enc.close(); } }
protected void add(ZipFile inFile, String password) throws IOException, UnsupportedEncodingException { ZipFileEntryInputStream zfe = new ZipFileEntryInputStream(inFile.getName()); try { Enumeration<? extends ZipEntry> en = inFile.entries(); while (en.hasMoreElements()) { ZipEntry ze = en.nextElement(); zfe.nextEntry(ze); add(ze, zfe, password); } } finally { zfe.close(); } }
/** * Zip + encrypt one "inFile" to one "outZipFile" using "password". */ public static void zipAndEncrypt(File inFile, File outFile, String password, AESEncrypter encrypter) throws IOException { AesZipFileEncrypter enc = new AesZipFileEncrypter(outFile,encrypter); try { enc.add(inFile, password); } finally { enc.close(); } }