public static Encryptor getInstance(EncryptionInfo info) { return info.getEncryptor(); }
final byte xorArray[] = getEncryptionInfo().getEncryptor().getSecretKey().getEncoded(); final byte chunk[] = getChunk(); final byte plain[] = (plainBytes.isEmpty()) ? null : chunk.clone();
outFS.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete(); Encryptor encGen = ei.getEncryptor(); if (!(encGen instanceof CryptoAPIEncryptor)) { throw new EncryptedDocumentException(
return; Encryptor enc = ei.getEncryptor(); int initialOffset = 0; LittleEndianByteArrayInputStream plain = new LittleEndianByteArrayInputStream(buf, 0); // NOSONAR
byte encVer[] = ver.getEncryptedVerifier(); Decryptor dec = ei.getDecryptor(); Encryptor enc = ei.getEncryptor(); try { if (encVer == null || !dec.verifyPassword(password)) {
public static Encryptor getInstance(EncryptionInfo info) { return info.getEncryptor(); }
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();
final byte xorArray[] = getEncryptionInfo().getEncryptor().getSecretKey().getEncoded(); final byte chunk[] = getChunk(); final byte plain[] = (plainBytes.isEmpty()) ? null : chunk.clone();
try { EncryptionInfo info = new EncryptionInfo(this.encryptionModeCipher, this.encryptAlgorithmCipher, this.hashAlgorithmCipher, -1, -1, this.chainModeCipher); Encryptor enc = info.getEncryptor(); enc.confirmPassword(this.howc.getPassword());
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); } }
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; }
si.confirmSignature(); Encryptor enc = info.getEncryptor(); enc.confirmPassword(password); POIFSFileSystem poifs = new POIFSFileSystem();
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); } }
outFS.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete(); Encryptor encGen = ei.getEncryptor(); if (!(encGen instanceof CryptoAPIEncryptor)) { throw new EncryptedDocumentException(
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); } } }
byte encVer[] = ver.getEncryptedVerifier(); Decryptor dec = ei.getDecryptor(); Encryptor enc = ei.getEncryptor(); try { if (encVer == null || !dec.verifyPassword(password)) {