public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
public Biff8DecryptingStream(InputStream in, int initialOffset, EncryptionInfo info) throws RecordFormatException { try { byte initialBuf[] = IOUtils.safelyAllocate(initialOffset, MAX_RECORD_LENGTH); InputStream stream; if (initialOffset == 0) { stream = in; } else { stream = new PushbackInputStream(in, initialOffset); ((PushbackInputStream)stream).unread(initialBuf); } Decryptor dec = info.getDecryptor(); dec.setChunkSize(RC4_REKEYING_INTERVAL); ccis = (ChunkedCipherInputStream)dec.getDataStream(stream, Integer.MAX_VALUE, 0); if (initialOffset > 0) { ccis.readFully(initialBuf); } } catch (Exception e) { throw new RecordFormatException(e); } }
return d.getDataStream(root); } else if (password != null) { throw new EncryptedDocumentException("Password incorrect");
private static POITextExtractor createEncryptedOOXMLExtractor(POIFSFileSystem fs) throws IOException { String pass = Biff8EncryptionKey.getCurrentUserPassword(); if (pass == null) { pass = Decryptor.DEFAULT_PASSWORD; } EncryptionInfo ei = new EncryptionInfo(fs); Decryptor dec = ei.getDecryptor(); InputStream is = null; try { if (!dec.verifyPassword(pass)) { throw new EncryptedDocumentException("Invalid password specified - use Biff8EncryptionKey.setCurrentUserPassword() before calling extractor"); } is = dec.getDataStream(fs); return createExtractor(OPCPackage.open(is)); } catch (IOException e) { throw e; } catch (Exception e) { throw new EncryptedDocumentException(e); } finally { IOUtils.closeQuietly(is); // also close the NPOIFSFileSystem here as we read all the data // while decrypting fs.close(); } } }
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("protect.xlsx")); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = new Decryptor(info); d.verifyPassword(Decryptor.DEFAULT_PASSWORD); XSSFWorkbook wb = new XSSFWorkbook(d.getDataStream(fs));
POIFSFileSystem filesystem = --> get your filesystem EncryptionInfo encInfo = new EncryptionInfo(filesystem); Decryptor decryptor = new Decryptor(encInfo); decryptor.verifyPassword("your-password"); XSSFWorkbook wb = new XSSFWorkbook(decryptor.getDataStream(filesystem))
EncryptionInfo info = new EncryptionInfo(filesystem); Decryptor d = Decryptor.getInstance(info); try { if (!d.verifyPassword(password)) { throw new RuntimeException("Unable to process: document is encrypted"); } InputStream dataStream = d.getDataStream(filesystem); XSSFWorkbook wb = new XSSFWorkbook(dataStream); // Process XLSX file here } catch (GeneralSecurityException ex) { throw new RuntimeException("Unable to process encrypted document", ex); }
POIFSFileSystem pfs = newPOIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("yourexcelfile.xlsx")); EncryptionInfo encInfo = new EncryptionInfo(pfs); Decryptor decryptor = new Decryptor(encInfo); decryptor.verifyPassword("ABCXYZ"); XSSFWorkbook wb = new XSSFWorkbook(decryptor.getDataStream(pfs));
EncryptionInfo info = new EncryptionInfo(filesystem); Decryptor d = Decryptor.getInstance(info); try { if (!d.verifyPassword(password)) { throw new RuntimeException("Unable to process: document is encrypted"); } InputStream dataStream = d.getDataStream(filesystem); HSSFWorkbook wb = new HSSFWorkbook(dataStream); // parse dataStream } catch (GeneralSecurityException ex) { throw new RuntimeException("Unable to process encrypted document", ex); }
EncryptionInfo info = new EncryptionInfo(filesystem); Decryptor d = Decryptor.getInstance(info); try { if (!d.verifyPassword(password)) { throw new RuntimeException("Unable to process: document is encrypted"); } InputStream dataStream = d.getDataStream(filesystem); // parse dataStream } catch (GeneralSecurityException ex) { throw new RuntimeException("Unable to process encrypted document", ex); }
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
public InputStream getDataStream(NPOIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
public InputStream getDataStream(POIFSFileSystem fs) throws IOException, GeneralSecurityException { return getDataStream(fs.getRoot()); }
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("protect.xlsx")); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword(Decryptor.DEFAULT_PASSWORD); XSSFWorkbook wb = new XSSFWorkbook(d.getDataStream(fs));
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File("D://protectedfile.xlsx")); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.getInstance(info); if (d.verifyPassword("password")) { XSSFWorkbook wb = new XSSFWorkbook(d.getDataStream(fs)); } else { // Password is wrong }
InputStream fin = new FileInputStream(xlsFile); BufferedInputStream in = new BufferedInputStream(fin); if (POIFSFileSystem.hasPOIFSHeader(in)) { // if there is any encryption POIFSFileSystem fs = new POIFSFileSystem(in); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword(Decryptor.DEFAULT_PASSWORD); workbook = WorkbookFactory.create(d.getDataStream(fs)); } else // without encryption workbook = WorkbookFactory.create(in);
public static InputStream decrypt(final InputStream inputStream, final String pwd) throws Exception { try { POIFSFileSystem fs = new POIFSFileSystem(inputStream); EncryptionInfo info = new EncryptionInfo(fs); Decryptor d = Decryptor.getInstance(info); if (!d.verifyPassword(pwd)) { throw new RuntimeException("incorrect password"); } return d.getDataStream(fs); } finally { IOUtils.closeQuietly(inputStream); } } }
parser.parse(d.getDataStream(root), new EmbeddedContentHandler( new BodyContentHandler(xhtml)), metadata, context);
private void decryptPicBytes(byte[] pictstream, int offset, int len) throws IOException, GeneralSecurityException { // when reading the picture elements, each time a segment is read, the cipher needs // to be reset (usually done when calling Cipher.doFinal) LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(pictstream, offset); Decryptor dec = getEncryptionInfo().getDecryptor(); ChunkedCipherInputStream ccis = (ChunkedCipherInputStream)dec.getDataStream(lei, len, 0); readFully(ccis, pictstream, offset, len); ccis.close(); lei.close(); }