use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestDocumentEncryption method cryptoAPIDecryption.
@Test
public void cryptoAPIDecryption() throws Exception {
// taken from a msdn blog:
// http://blogs.msdn.com/b/openspecification/archive/2009/05/08/dominic-salemno.aspx
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile("cryptoapi-proc2356.ppt"));
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
HSLFSlideShow ss = new HSLFSlideShow(hss);
HSLFSlide slide = ss.getSlides().get(0);
String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));
assertEquals("Dominic Salemno", rawText);
String[][] picCmp = { { "0", "nKsDTKqxTCR8LFkVVWlP9GSTvZ0=" }, { "95163", "SuNOR+9V1UVYZIoeD65l3VTaLoc=" }, { "100864", "Ql3IGrr4bNq07ZTp5iPg7b+pva8=" }, { "714114", "8pdst9NjBGSfWezSZE8+aVhIRe0=" }, { "723752", "go6xqW7lvkCtlOO5tYLiMfb4oxw=" }, { "770128", "gZUM8YqRNL5kGNfyyYvEEernvCc=" }, { "957958", "CNU2iiqUFAnk3TDXsXV1ihH9eRM=" } };
MessageDigest md = CryptoFunctions.getMessageDigest(HashAlgorithm.sha1);
List<HSLFPictureData> pd = hss.getPictureData();
int i = 0;
for (HSLFPictureData p : pd) {
byte[] hash = md.digest(p.getData());
assertEquals(Integer.parseInt(picCmp[i][0]), p.getOffset());
assertEquals(picCmp[i][1], Base64.encodeBase64String(hash));
i++;
}
DocumentEncryptionAtom dea = hss.getDocumentEncryptionAtom();
POIFSFileSystem fs2 = ((CryptoAPIDecryptor) dea.getEncryptionInfo().getDecryptor()).getSummaryEntries(fs.getRoot(), "EncryptedSummary");
PropertySet ps = PropertySetFactory.create(fs2.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isSummaryInformation());
assertEquals("RC4 CryptoAPI Encryption", ps.getProperties()[1].getValue());
ps = PropertySetFactory.create(fs2.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isDocumentSummaryInformation());
assertEquals("On-screen Show (4:3)", ps.getProperties()[1].getValue());
ss.close();
fs.close();
fs2.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShowImpl in project poi by apache.
the class TestDocumentEncryption method cryptoAPIEncryption.
@Test
public void cryptoAPIEncryption() throws Exception {
/* documents with multiple edits need to be normalized for encryption */
String pptFile = "57272_corrupted_usereditatom.ppt";
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
hss.normalizeRecords();
// normalized ppt
ByteArrayOutputStream expected = new ByteArrayOutputStream();
hss.write(expected);
// encrypted
Biff8EncryptionKey.setCurrentUserPassword("hello");
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
hss.write(encrypted);
hss.close();
fs.close();
// decrypted
ByteArrayInputStream bis = new ByteArrayInputStream(encrypted.toByteArray());
fs = new NPOIFSFileSystem(bis);
hss = new HSLFSlideShowImpl(fs);
Biff8EncryptionKey.setCurrentUserPassword(null);
ByteArrayOutputStream actual = new ByteArrayOutputStream();
hss.write(actual);
hss.close();
fs.close();
assertArrayEquals(expected.toByteArray(), actual.toByteArray());
}
Aggregations