public OutputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
byte tmp[] = new byte[1024]; try { ChunkedCipherOutputStream os = enc.getDataStream(leos, initialOffset); int totalBytes = 0; while (totalBytes < buf.length) {
public OutputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile); Encryptor enc = info.getEncryptor(); enc.confirmPassword("xxxxx"); OPCPackage opc = OPCPackage.open(new File("c:/test/sample.xlsx"),PackageAccess.READ_WRITE); OutputStream os = enc.getDataStream(fs); opc.save(os); opc.close(); FileOutputStream fos = new FileOutputStream("c:/test/sample.xlsx"); fs.writeFilesystem(fos); fos.close();
// create a new POIFSFileSystem, which is the container for // encrypted OOXML-based files POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); // setup the encryption Encryptor enc = info.getEncryptor(); enc.confirmPassword("foobaa"); // after writing to the SXSSF workbook you need the content // as a stream InputStream is = <open the SXSSF workbook as stream> OutputStream os = enc.getDataStream(fs); // copy the stream to the OutputStream IOUtils.copy(is, os); // Write out the encrypted version FileOutputStream fos = new FileOutputStream("..."); fs.writeFilesystem(fos); fos.close();
// Prepare POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null); Encryptor enc = info.getEncryptor(); enc.confirmPassword("foobaa"); // Create the normal workbook Workbook wb = new XSSFWorkbook(); Sheet s = wb.createSheet(); // TODO Populate // Encrypt OutputStream os = enc.getDataStream(fs); wb.save(os); opc.close(); // Save FileOutputStream fos = new FileOutputStream("protected.xlsx"); fs.writeFilesystem(fos); fos.close();
os = enc.getDataStream(ooxmlDocumentFileSystem); if (os!=null) { this.currentWorkbook.write(os);
private void encryptBytes(byte[] plain, int encryptOffset, OutputStream bos) throws IOException { try { EncryptionInfo ei = getEncryptionInfo(); Encryptor enc = ei.getEncryptor(); enc.setChunkSize(RC4_REKEYING_INTERVAL); ChunkedCipherOutputStream os = enc.getDataStream(bos, 0); if (encryptOffset > 0) { os.writePlain(plain, 0, encryptOffset); } os.write(plain, encryptOffset, plain.length-encryptOffset); os.close(); } catch (GeneralSecurityException e) { throw new IOException(e); } }
public static void save(final InputStream inputStream, final String filename, final String pwd) throws InvalidFormatException, IOException, GeneralSecurityException { try (POIFSFileSystem fs = new POIFSFileSystem(); OPCPackage opc = OPCPackage.open(inputStream); FileOutputStream fos = new FileOutputStream(filename)) { EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); Encryptor enc = Encryptor.getInstance(info); enc.confirmPassword(pwd); opc.save(enc.getDataStream(fs)); fs.writeFilesystem(fos); } finally { IOUtils.closeQuietly(inputStream); } }
private void encryptFile() throws Exception { if (StringUtils.isNotBlank(this.password)) { if (this.getIsXlsxFile()) { final POIFSFileSystem fs = new POIFSFileSystem(); final EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile); final Encryptor enc = info.getEncryptor(); enc.confirmPassword(this.password); final OPCPackage opc = OPCPackage.open(this.spreadsheetFile, PackageAccess.READ_WRITE); OutputStream os = enc.getDataStream(fs); opc.save(os); opc.close(); this.writeFile(fs); } } }
protected OutputStream encryptRecord(OutputStream plainStream, int persistId, Record record) { boolean isPlain = (dea == null || record instanceof UserEditAtom || record instanceof PersistPtrHolder || record instanceof DocumentEncryptionAtom ); try { if (isPlain) { if (cyos != null) { // write cached data to stream cyos.flush(); } return plainStream; } if (cyos == null) { Encryptor enc = getEncryptionInfo().getEncryptor(); enc.setChunkSize(-1); cyos = enc.getDataStream(plainStream, 0); } cyos.initCipherForBlock(persistId, false); } catch (Exception e) { throw new EncryptedPowerPointFileException(e); } return cyos; }
OutputStream os = enc.getDataStream(fs); if (os!=null) { this.currentWorkbook.write(os);
enc.confirmPassword(password); POIFSFileSystem poifs = new POIFSFileSystem(); OutputStream os = enc.getDataStream(poifs); pkg.save(os); pkg.close();
byte tmp[] = new byte[1024]; try { ChunkedCipherOutputStream os = enc.getDataStream(leos, initialOffset); int totalBytes = 0; while (totalBytes < buf.length) {
Encryptor enc = getEncryptionInfo().getEncryptor(); enc.setChunkSize(-1); ccos = enc.getDataStream(los, 0); int recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset)); int recType = LittleEndian.getUShort(pictstream, offset+2);