if (password != null && d.verifyPassword(password)) { passwordCorrect = true; if (!passwordCorrect && d.verifyPassword(Decryptor.DEFAULT_PASSWORD)) { passwordCorrect = true;
public RecordInputStream createDecryptingStream(InputStream original) { String userPassword = Biff8EncryptionKey.getCurrentUserPassword(); if (userPassword == null) { userPassword = Decryptor.DEFAULT_PASSWORD; } EncryptionInfo info = _filePassRec.getEncryptionInfo(); try { if (!info.getDecryptor().verifyPassword(userPassword)) { throw new EncryptedDocumentException( (Decryptor.DEFAULT_PASSWORD.equals(userPassword) ? "Default" : "Supplied") + " password is invalid for salt/verifier/verifierHash"); } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException(e); } return new RecordInputStream(original, info, _initialRecordsSize); }
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));
Encryptor enc = ei.getEncryptor(); try { if (encVer == null || !dec.verifyPassword(password)) { enc.confirmPassword(password); } else {
public boolean isValid(String password) throws GeneralSecurityException { return d.verifyPassword(password); }
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 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))
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); }
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 }
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));
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);
try { InputStream is = new FileInputStream("myfile.xlsx"); POIFSFileSystem pfs = new POIFSFileSystem(is); EncryptionInfo info = new EncryptionInfo(pfs); Decryptor d = Decryptor.getInstance(info); if (!d.verifyPassword("passwordForFile")) { System.out.println("Incorrect password!"); } else { System.out.println("Correct password!"); //InputStream dataStream = d.getDataStream(pfs); // parse dataStream } } catch (Exception ex) { throw new RuntimeException("Unable to process encrypted document", ex); }
private InputStream getProtectedInputStreamForXlsx() { try { final POIFSFileSystem fileSystem = new POIFSFileSystem(new FileInputStream(this.spreadsheetFile)); final EncryptionInfo encryptionInfo = new EncryptionInfo(fileSystem); final Decryptor decryptor = Decryptor.getInstance(encryptionInfo); decryptor.verifyPassword(this.password); return decryptor.getDataStream(fileSystem); } catch (Exception e) { final String message = "Failed to open file with the given password: " + e.getMessage(); LOGGER.error(message); throw new RuntimeException(message); } }
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); } } }
if (!d.verifyPassword(password)) { throw new EncryptedDocumentException();
public RecordInputStream createDecryptingStream(InputStream original) { String userPassword = Biff8EncryptionKey.getCurrentUserPassword(); if (userPassword == null) { userPassword = Decryptor.DEFAULT_PASSWORD; } EncryptionInfo info = _filePassRec.getEncryptionInfo(); try { if (!info.getDecryptor().verifyPassword(userPassword)) { throw new EncryptedDocumentException( (Decryptor.DEFAULT_PASSWORD.equals(userPassword) ? "Default" : "Supplied") + " password is invalid for salt/verifier/verifierHash"); } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException(e); } return new RecordInputStream(original, info, _initialRecordsSize); }
public void init(File f) { try { if (builder.getPassword() != null) { // Based on: https://poi.apache.org/encryption.html POIFSFileSystem poifs = new POIFSFileSystem(f); EncryptionInfo info = new EncryptionInfo(poifs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword(builder.getPassword()); pkg = OPCPackage.open(d.getDataStream(poifs)); } else { pkg = OPCPackage.open(f); } XSSFReader reader = new XSSFReader(pkg); SharedStringsTable sst = reader.getSharedStringsTable(); StylesTable styles = reader.getStylesTable(); loadSheets(reader, sst, styles, builder.getRowCacheSize()); } catch (IOException e) { throw new OpenException("Failed to open file", e); } catch (OpenXML4JException | XMLStreamException e) { throw new ReadException("Unable to read workbook", e); } catch (GeneralSecurityException e) { throw new ReadException("Unable to read workbook - Decryption failed", e); } }