public static Decryptor getInstance(EncryptionInfo info) { Decryptor d = info.getDecryptor(); if (d == null) { throw new EncryptedDocumentException("Unsupported version"); } return d; }
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); } }
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); }
@Override protected int invokeCipher(int totalBytes, boolean doFinal) { final int pos = (int)getPos(); final byte xorArray[] = getEncryptionInfo().getDecryptor().getSecretKey().getEncoded(); final byte chunk[] = getChunk(); final byte plain[] = getPlain();
throw new EncryptedDocumentException("can't find encrypted property stream '"+encryptedStream+"'"); CryptoAPIDecryptor dec = (CryptoAPIDecryptor)encryptionInfo.getDecryptor(); encPoifs = dec.getSummaryEntries(dirNode, encryptedStream); dirNode = encPoifs.getRoot();
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(); } } }
EncryptionVerifier ver = ei.getVerifier(); byte encVer[] = ver.getEncryptedVerifier(); Decryptor dec = ei.getDecryptor(); Encryptor enc = ei.getEncryptor(); try {
public static Decryptor getInstance(EncryptionInfo info) { Decryptor d = info.getDecryptor(); if (d == null) { throw new EncryptedDocumentException("Unsupported version"); } return d; }
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); } }
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 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(); }
EncryptionInfo ei = getEncryptionInfo(); try { if(!ei.getDecryptor().verifyPassword(pass != null ? pass : Decryptor.DEFAULT_PASSWORD)) { throw new EncryptedPowerPointFileException("PowerPoint file is encrypted. The correct password needs to be set via Biff8EncryptionKey.setCurrentUserPassword()");
@Override protected int invokeCipher(int totalBytes, boolean doFinal) { final int pos = (int)getPos(); final byte xorArray[] = getEncryptionInfo().getDecryptor().getSecretKey().getEncoded(); final byte chunk[] = getChunk(); final byte plain[] = getPlain();
protected void decryptRecord(byte[] docstream, int persistId, int offset) { if (dea == null) { return; } Decryptor dec = getEncryptionInfo().getDecryptor(); dec.setChunkSize(-1); try (LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(docstream, offset); ChunkedCipherInputStream ccis = (ChunkedCipherInputStream)dec.getDataStream(lei, docstream.length-offset, 0)) { ccis.initCipherForBlock(persistId); // decrypt header and read length to be decrypted readFully(ccis, docstream, offset, 8); // decrypt the rest of the record int rlen = (int)LittleEndian.getUInt(docstream, offset+4); readFully(ccis, docstream, offset+8, rlen); } catch (Exception e) { throw new EncryptedPowerPointFileException(e); } }
EncryptionMode em = fibBase.isFObfuscated() ? EncryptionMode.xor : null; EncryptionInfo ei = new EncryptionInfo(leis, em); Decryptor dec = ei.getDecryptor(); dec.setChunkSize(RC4_REKEYING_INTERVAL); try {
throw new EncryptedDocumentException("can't find encrypted property stream '"+encryptedStream+"'"); CryptoAPIDecryptor dec = (CryptoAPIDecryptor)encryptionInfo.getDecryptor(); encPoifs = dec.getSummaryEntries(dirNode, encryptedStream); dirNode = encPoifs.getRoot();
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(); } } }
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); } } }
EncryptionVerifier ver = ei.getVerifier(); byte encVer[] = ver.getEncryptedVerifier(); Decryptor dec = ei.getDecryptor(); Encryptor enc = ei.getEncryptor(); try {