use of org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException in project poi by apache.
the class HSLFSlideShowEncrypted method encryptRecord.
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;
}
encryptInit();
if (cyos == null) {
enc.setChunkSize(-1);
cyos = enc.getDataStream(plainStream, 0);
}
cyos.initCipherForBlock(persistId, false);
} catch (Exception e) {
throw new EncryptedPowerPointFileException(e);
}
return cyos;
}
use of org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException in project poi by apache.
the class HSLFSlideShowEncrypted method encryptPicture.
protected void encryptPicture(byte[] pictstream, int offset) {
if (dea == null) {
return;
}
encryptInit();
// NOSONAR
LittleEndianByteArrayOutputStream los = new LittleEndianByteArrayOutputStream(pictstream, offset);
ChunkedCipherOutputStream ccos = null;
try {
enc.setChunkSize(-1);
ccos = enc.getDataStream(los, 0);
int recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset));
int recType = LittleEndian.getUShort(pictstream, offset + 2);
final int rlen = (int) LittleEndian.getUInt(pictstream, offset + 4);
ccos.write(pictstream, offset, 8);
ccos.flush();
offset += 8;
int endOffset = offset + rlen;
if (recType == 0xF007) {
// TOOD: get a real example file ... to actual test the FBSE entry
// not sure where the foDelay block is
// File BLIP Store Entry (FBSE)
int cbName = LittleEndian.getUShort(pictstream, offset + 33);
for (int part : BLIB_STORE_ENTRY_PARTS) {
ccos.write(pictstream, offset, part);
ccos.flush();
offset += part;
}
if (cbName > 0) {
ccos.write(pictstream, offset, cbName);
ccos.flush();
offset += cbName;
}
if (offset == endOffset) {
// no embedded blip
return;
}
// fall through, read embedded blip now
// update header data
recInst = fieldRecInst.getValue(LittleEndian.getUShort(pictstream, offset));
recType = LittleEndian.getUShort(pictstream, offset + 2);
ccos.write(pictstream, offset, 8);
ccos.flush();
offset += 8;
}
int rgbUidCnt = (recInst == 0x217 || recInst == 0x3D5 || recInst == 0x46B || recInst == 0x543 || recInst == 0x6E1 || recInst == 0x6E3 || recInst == 0x6E5 || recInst == 0x7A9) ? 2 : 1;
for (int i = 0; i < rgbUidCnt; i++) {
// rgbUid 1/2
ccos.write(pictstream, offset, 16);
ccos.flush();
offset += 16;
}
if (recType == 0xF01A || recType == 0XF01B || recType == 0XF01C) {
// metafileHeader
ccos.write(pictstream, offset, 34);
offset += 34;
ccos.flush();
} else {
// tag
ccos.write(pictstream, offset, 1);
offset += 1;
ccos.flush();
}
int blipLen = endOffset - offset;
ccos.write(pictstream, offset, blipLen);
ccos.flush();
} catch (Exception e) {
throw new EncryptedPowerPointFileException(e);
} finally {
IOUtils.closeQuietly(ccos);
IOUtils.closeQuietly(los);
}
}
use of org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException 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);
}
}
use of org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException in project poi by apache.
the class TestDocumentEncryption method cryptoAPIDecryptionOther.
@Test
public void cryptoAPIDecryptionOther() throws Exception {
Biff8EncryptionKey.setCurrentUserPassword("hello");
String[] encPpts = { "Password_Protected-56-hello.ppt", "Password_Protected-hello.ppt", "Password_Protected-np-hello.ppt" };
for (String pptFile : encPpts) {
try {
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
new HSLFSlideShow(hss).close();
fs.close();
} catch (EncryptedPowerPointFileException e) {
fail(pptFile + " can't be decrypted");
}
}
}
Aggregations