Search in sources :

Example 16 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project poi by apache.

the class TestBasic method testPropertySetMethods.

/**
     * <p>Tests the {@link PropertySet} methods. The test file has two
     * property sets: the first one is a {@link SummaryInformation},
     * the second one is a {@link DocumentSummaryInformation}.</p>
     *
     * @exception IOException if an I/O exception occurs
     * @exception HPSFException if any HPSF exception occurs
     */
@Test
public void testPropertySetMethods() throws IOException, HPSFException {
    /* Loop over the two property sets. */
    for (int i = 0; i < 2; i++) {
        byte[] b = poiFiles.get(i).getBytes();
        PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
        assertEquals(BYTE_ORDER, ps.getByteOrder());
        assertEquals(FORMAT, ps.getFormat());
        assertEquals(OS_VERSION, ps.getOSVersion());
        assertEquals(CLASS_ID, ps.getClassID());
        assertEquals(SECTION_COUNT[i], ps.getSectionCount());
        assertEquals(IS_SUMMARY_INFORMATION[i], ps.isSummaryInformation());
        assertEquals(IS_DOCUMENT_SUMMARY_INFORMATION[i], ps.isDocumentSummaryInformation());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PropertySet(org.apache.poi.hpsf.PropertySet) Test(org.junit.Test)

Example 17 with PropertySet

use of org.apache.poi.hpsf.PropertySet 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();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) PropertySet(org.apache.poi.hpsf.PropertySet) MessageDigest(java.security.MessageDigest) HSLFPictureData(org.apache.poi.hslf.usermodel.HSLFPictureData) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) CryptoAPIDecryptor(org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIDecryptor) Test(org.junit.Test)

Aggregations

PropertySet (org.apache.poi.hpsf.PropertySet)17 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)6 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)6 MutablePropertySet (org.apache.poi.hpsf.MutablePropertySet)5 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)5 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)5 MutableSection (org.apache.poi.hpsf.MutableSection)4 Section (org.apache.poi.hpsf.Section)4 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 NoPropertySetStreamException (org.apache.poi.hpsf.NoPropertySetStreamException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2