public FilePassRecord(EncryptionMode encryptionMode) { encryptionType = (encryptionMode == EncryptionMode.xor) ? ENCRYPTION_XOR : ENCRYPTION_OTHER; encryptionInfo = new EncryptionInfo(encryptionMode); }
public FilePassRecord(RecordInputStream in) { encryptionType = in.readUShort(); EncryptionMode preferredMode; switch (encryptionType) { case ENCRYPTION_XOR: preferredMode = EncryptionMode.xor; break; case ENCRYPTION_OTHER: preferredMode = EncryptionMode.cryptoAPI; break; default: throw new EncryptedDocumentException("invalid encryption type"); } try { encryptionInfo = new EncryptionInfo(in, preferredMode); } catch (IOException e) { throw new EncryptedDocumentException(e); } }
EncryptionInfo info = new EncryptionInfo(root); Decryptor d = Decryptor.getInstance(info);
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(); } } }
public FilePassRecord(EncryptionMode encryptionMode) { encryptionType = (encryptionMode == EncryptionMode.xor) ? ENCRYPTION_XOR : ENCRYPTION_OTHER; encryptionInfo = new EncryptionInfo(encryptionMode); }
/** * Initializes the encryption settings * * @param keyBits see {@link CipherAlgorithm#rc4} for allowed values, use -1 for default size */ public void initializeEncryptionInfo(int keyBits) { ei = new EncryptionInfo(EncryptionMode.cryptoAPI, CipherAlgorithm.rc4, HashAlgorithm.sha1, keyBits, -1, null); }
private OOXMLPasswordsTry(POIFSFileSystem fs) throws IOException { info = new EncryptionInfo(fs); d = Decryptor.getInstance(info); this.fs = fs; } private OOXMLPasswordsTry(File file) throws IOException {
/** * For the Document Encryption Atom */ protected DocumentEncryptionAtom(byte[] source, int start, int len) { // Get the header _header = new byte[8]; System.arraycopy(source,start,_header,0,8); ByteArrayInputStream bis = new ByteArrayInputStream(source, start+8, len-8); try (LittleEndianInputStream leis = new LittleEndianInputStream(bis)) { ei = new EncryptionInfo(leis, EncryptionMode.cryptoAPI); } catch (IOException e) { throw new EncryptedDocumentException(e); } }
public DocumentEncryptionAtom() { _header = new byte[8]; LittleEndian.putShort(_header, 0, (short)0x000F); LittleEndian.putShort(_header, 2, (short)_type); // record length not yet known ... ei = new EncryptionInfo(EncryptionMode.cryptoAPI); }
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 FilePassRecord(RecordInputStream in) { encryptionType = in.readUShort(); EncryptionMode preferredMode; switch (encryptionType) { case ENCRYPTION_XOR: preferredMode = EncryptionMode.xor; break; case ENCRYPTION_OTHER: preferredMode = EncryptionMode.cryptoAPI; break; default: throw new EncryptedDocumentException("invalid encryption type"); } try { encryptionInfo = new EncryptionInfo(in, preferredMode); } catch (IOException e) { throw new EncryptedDocumentException(e); } }
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); } } }
break; case ENCRYPTED: EncryptionInfo info = new EncryptionInfo(root); Decryptor d = Decryptor.getInstance(info);
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); } }
EncryptionInfo info = new EncryptionInfo(poifs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword(builder.getPassword());
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); } } }
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(); } } }
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); } }
protected void updateEncryptionInfo() { // make sure, that we've read all the streams ... readProperties(); // now check for the password String password = Biff8EncryptionKey.getCurrentUserPassword(); FibBase fBase = _fib.getFibBase(); if (password == null) { fBase.setLKey(0); fBase.setFEncrypted(false); fBase.setFObfuscated(false); _encryptionInfo = null; } else { // create password record if (_encryptionInfo == null) { _encryptionInfo = new EncryptionInfo(EncryptionMode.cryptoAPI); fBase.setFEncrypted(true); fBase.setFObfuscated(false); } Encryptor enc = _encryptionInfo.getEncryptor(); byte salt[] = _encryptionInfo.getVerifier().getSalt(); if (salt == null) { enc.confirmPassword(password); } else { byte verifier[] = _encryptionInfo.getDecryptor().getVerifier(); enc.confirmPassword(password, null, null, verifier, salt, null); } } }
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); } }