• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StandardProtectionPolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy的典型用法代码示例。如果您正苦于以下问题:Java StandardProtectionPolicy类的具体用法?Java StandardProtectionPolicy怎么用?Java StandardProtectionPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StandardProtectionPolicy类属于org.apache.pdfbox.pdmodel.encryption包,在下文中一共展示了StandardProtectionPolicy类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getDocument

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
private PDDocument getDocument(RandomAccessRead source) throws IOException, BleachException {
    PDDocument doc;
    for (String pwd : COMMON_PASSWORDS) {
        ScratchFile scratchFile = new ScratchFile(MEMORY_USAGE_SETTING);
        doc = testPassword(scratchFile, source, pwd);
        if (doc != null) {
            LOGGER.debug("Password was guessed: '{}'", pwd);
            doc.protect(new StandardProtectionPolicy(pwd, pwd, doc.getCurrentAccessPermission()));
            return doc;
        }
        scratchFile.close();
    }

    // @TODO: fetch password from config?

    throw new BleachException("PDF is protected with an unknown password");
}
 
开发者ID:docbleach,项目名称:DocBleach,代码行数:18,代码来源:PdfBleach.java


示例2: protect

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Override
public void protect(final String inputUri, final String outputUri, final String password)
		throws IOException, BadSecurityHandlerException, COSVisitorException {

	if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
			&& StringUtils.isNotBlank(password)) {

		final PDDocument doc = PDDocument.load(inputUri);

		final StandardProtectionPolicy pp = new StandardProtectionPolicy(password, password,
				new AccessPermission());
		doc.protect(pp);

		doc.save(outputUri);

		doc.close();

	} else {
		throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:22,代码来源:PDFGalImpl.java


示例3: unProtect

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Override
public void unProtect(final String inputUri, final String outputUri, final String password)
		throws IOException, COSVisitorException, BadSecurityHandlerException,
		CryptographyException {

	if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
			&& StringUtils.isNotBlank(password)) {

		final PDDocument doc = PDDocument.load(inputUri);

		final DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(password);
		doc.openProtection(decryptionMaterial);

		final StandardProtectionPolicy pp = new StandardProtectionPolicy(null, null,
				new AccessPermission());
		doc.protect(pp);

		doc.save(outputUri);

		doc.close();

	} else {
		throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:26,代码来源:PDFGalImpl.java


示例4: init

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);
	File file = new File(GR.getGoldenDir(), goldenFileName);
	try {
		in = new ByteArrayInputStream(MTTestResourceManager.goldenFileToByteArray(file.getPath()));
		out = new ByteArrayOutputStream();
		AccessPermission ap = new AccessPermission();
		policy = new StandardProtectionPolicy(ownerPass, userPass, ap);
	} catch (IOException e) {
		throw new InvalidTestFormatException ("file not found " + e.getMessage() + " " + file.getAbsolutePath(), this.getClass());
	}
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:14,代码来源:Encryption.java


示例5: doCreate

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
private OutputStream doCreate(Exchange exchange) throws IOException, BadSecurityHandlerException, COSVisitorException {
    LOG.debug("Got {} operation, going to create and write provided string to pdf document.",
            pdfConfiguration.getOperation());
    String body = exchange.getIn().getBody(String.class);
    PDDocument document = new PDDocument();
    StandardProtectionPolicy protectionPolicy = exchange.getIn().getHeader(
            PROTECTION_POLICY_HEADER_NAME, StandardProtectionPolicy.class);
    appendToPdfDocument(body, document, protectionPolicy);
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    document.save(byteArrayOutputStream);
    return byteArrayOutputStream;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:PdfProducer.java


示例6: testPdfCreationWithEncryption

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Test
public void testPdfCreationWithEncryption() throws Exception {
    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    final String expectedText = "expectedText";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanPrint(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);
    template.sendBodyAndHeader("direct:start",
            expectedText,
            PdfHeaderConstants.PROTECTION_POLICY_HEADER_NAME,
            protectionPolicy);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
                PDDocument doc = PDDocument.load(new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
                assertTrue("Expected encrypted document", doc.isEncrypted());
                doc.decrypt(userPass);
                assertFalse("Printing should not be permitted", doc.getCurrentAccessPermission().canPrint());
                PDFTextStripper pdfTextStripper = new PDFTextStripper();
                String text = pdfTextStripper.getText(doc);
                assertEquals(1, doc.getNumberOfPages());
                assertThat(text, containsString(expectedText));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:PdfCreationTest.java


示例7: generate

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Override
public ByteArrayOutputStream generate( Invoice invoice ) throws IOException
{
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    Resource resource = resourceLoader.getResource( templateLocation );

    try ( PDDocument pdfDocument = PDDocument.load( resource.getInputStream() ) )
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        acroForm.setCacheFields( true );

        setFields( invoice, acroForm );
        acroForm.getFieldIterator().forEachRemaining( pdField -> pdField.setReadOnly( true ) );

        AccessPermission ap = new AccessPermission();
        ap.setCanModify( false );
        ap.setReadOnly();
        StandardProtectionPolicy spp = new StandardProtectionPolicy( UUID.randomUUID().toString(), "", ap );
        spp.setEncryptionKeyLength( 128 );
        pdfDocument.protect( spp );

        pdfDocument.save( out );
    }

    return out;
}
 
开发者ID:ClouDesire,项目名称:janine,代码行数:29,代码来源:PdfServiceImpl.java


示例8: testExtractTextFromEncrypted

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Test
public void testExtractTextFromEncrypted() throws Exception {
    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanExtractContent(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);
    PDDocument document = new PDDocument();

    final String expectedText = "Test string";
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(expectedText);
    contentStream.endText();
    contentStream.close();

    document.protect(protectionPolicy);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    document.save(output);

    // Encryption happens after saving.
    PDDocument encryptedDocument = PDDocument.load(new ByteArrayInputStream(output.toByteArray()));

    template.sendBodyAndHeader("direct:start",
            encryptedDocument,
            PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME,
            new StandardDecryptionMaterial(userPass));

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(String.class));
            assertThat((String) body, containsString(expectedText));
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();
    document.isEncrypted();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:48,代码来源:PdfTextExtractionTest.java


示例9: testAppendEncrypted

import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; //导入依赖的package包/类
@Test
public void testAppendEncrypted() throws Exception {
    final String originalText = "Test";
    final String textToAppend = "Append";
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(originalText);
    contentStream.endText();
    contentStream.close();

    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanExtractContent(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);

    document.protect(protectionPolicy);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    document.save(output);

    // Encryption happens after saving.
    PDDocument encryptedDocument = PDDocument.load(new ByteArrayInputStream(output.toByteArray()));

    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(PdfHeaderConstants.PDF_DOCUMENT_HEADER_NAME, encryptedDocument);
    headers.put(PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME, new StandardDecryptionMaterial(userPass));

    template.sendBodyAndHeaders("direct:start", textToAppend, headers);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
                PDDocument doc = PDDocument.load(new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
                PDFTextStripper pdfTextStripper = new PDFTextStripper();
                String text = pdfTextStripper.getText(doc);
                assertEquals(2, doc.getNumberOfPages());
                assertThat(text, containsString(originalText));
                assertThat(text, containsString(textToAppend));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:59,代码来源:PdfAppendTest.java



注:本文中的org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SortHandlerMethodArgumentResolver类代码示例发布时间:2022-05-22
下一篇:
Java AssociationSessionType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap