Search in sources :

Example 1 with ChunkedCipherInputStream

use of org.apache.poi.poifs.crypt.ChunkedCipherInputStream in project poi by apache.

the class HSLFSlideShowEncrypted method decryptPicBytes.

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);
    ChunkedCipherInputStream ccis = dec.getDataStream(lei, len, 0);
    readFully(ccis, pictstream, offset, len);
    ccis.close();
    lei.close();
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ChunkedCipherInputStream(org.apache.poi.poifs.crypt.ChunkedCipherInputStream)

Example 2 with ChunkedCipherInputStream

use of org.apache.poi.poifs.crypt.ChunkedCipherInputStream in project poi by apache.

the class HSLFSlideShowEncrypted method decryptRecord.

protected void decryptRecord(byte[] docstream, int persistId, int offset) {
    if (dea == null) {
        return;
    }
    decryptInit();
    dec.setChunkSize(-1);
    // NOSONAR
    LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(docstream, offset);
    ChunkedCipherInputStream ccis = null;
    try {
        ccis = 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);
    } finally {
        IOUtils.closeQuietly(ccis);
        IOUtils.closeQuietly(lei);
    }
}
Also used : LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ChunkedCipherInputStream(org.apache.poi.poifs.crypt.ChunkedCipherInputStream) EncryptedPowerPointFileException(org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException) EncryptedPowerPointFileException(org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) CorruptPowerPointFileException(org.apache.poi.hslf.exceptions.CorruptPowerPointFileException) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException)

Aggregations

ChunkedCipherInputStream (org.apache.poi.poifs.crypt.ChunkedCipherInputStream)2 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)2 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)1 CorruptPowerPointFileException (org.apache.poi.hslf.exceptions.CorruptPowerPointFileException)1 EncryptedPowerPointFileException (org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException)1