try { if (encVer == null || !dec.verifyPassword(password)) { enc.confirmPassword(password); } else { byte verifier[] = dec.getVerifier(); byte salt[] = ver.getSalt(); enc.confirmPassword(password, null, null, verifier, salt, null);
POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile); Encryptor enc = info.getEncryptor(); enc.confirmPassword(<your_password>); OPCPackage opc = OPCPackage.open(new File(<file_path>), PackageAccess.READ_WRITE); //opening package for encryption OutputStream os = enc.getDataStream(fs); //perform encryption opc.save(os); //save package opc.close(); FileOutputStream fos = new FileOutputStream("file_path"); fs.writeFilesystem(fos); //write the file back to file system fos.close();
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();
EncryptionInfo info = new EncryptionInfo(this.encryptionModeCipher, this.encryptAlgorithmCipher, this.hashAlgorithmCipher, -1, -1, this.chainModeCipher); Encryptor enc = info.getEncryptor(); enc.confirmPassword(this.howc.getPassword());
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 Record[] updateEncryptionRecord(Record records[]) { String password = Biff8EncryptionKey.getCurrentUserPassword(); if (password == null) { if (dea == null) { // no password given, no encryption record exits -> done return records; } else { // need to remove password data dea = null; return removeEncryptionRecord(records); } } else { // create password record if (dea == null) { dea = new DocumentEncryptionAtom(); } EncryptionInfo ei = dea.getEncryptionInfo(); byte salt[] = ei.getVerifier().getSalt(); Encryptor enc = getEncryptionInfo().getEncryptor(); if (salt == null) { enc.confirmPassword(password); } else { byte verifier[] = ei.getDecryptor().getVerifier(); enc.confirmPassword(password, null, null, verifier, salt, null); } // move EncryptionRecord to last slide position records = normalizeRecords(records); return addEncryptionRecord(records, dea); } }
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); } } }
Encryptor enc = info.getEncryptor(); enc.confirmPassword(this.howc.getPassword()); try { OutputStream os = enc.getDataStream(fs);
try { if (encVer == null || !dec.verifyPassword(password)) { enc.confirmPassword(password); } else { byte verifier[] = dec.getVerifier(); byte salt[] = ver.getSalt(); enc.confirmPassword(password, null, null, verifier, salt, null);
enc.confirmPassword(password); POIFSFileSystem poifs = new POIFSFileSystem(); OutputStream os = enc.getDataStream(poifs);