Examples of PublicKeyProtectionPolicy


Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

                if( !document.isEncrypted() )
                {
                    if( certFile != null )
                    {
                        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
                        PublicKeyRecipient recip = new PublicKeyRecipient();
                        recip.setPermission(ap);


                        CertificateFactory cf = CertificateFactory.getInstance("X.509");
                        InputStream inStream = new FileInputStream(certFile);
                        X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
                        inStream.close();

                        recip.setX509(certificate);

                        ppp.addRecipient(recip);

                        ppp.setEncryptionKeyLength(keyLength);

                        document.protect(ppp);
                    }
                    else
                    {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an unexpected error during the test.
     */
    public void testProtectionError() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        document.protect(policy);

        PDDocument encryptedDoc = reload(document);
        try
        {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an unexpected error during the test.
     */
    public void testProtection() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        document.protect(policy);

        PDDocument encryptedDoc = reload(document);
        try
        {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an error during the test.
     */
    public void testMultipleRecipients() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        policy.addRecipient(recipient2);
        document.protect(policy);

        // open first time
        PDDocument encryptedDoc1 = reload(document);
        try
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

                if( !document.isEncrypted() )
                {
                    if( certFile != null )
                    {
                        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
                        PublicKeyRecipient recip = new PublicKeyRecipient();
                        recip.setPermission(ap);


                        CertificateFactory cf = CertificateFactory.getInstance("X.509");
                        InputStream inStream = new FileInputStream(certFile);
                        X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
                        inStream.close();

                        recip.setX509(certificate);

                        ppp.addRecipient(recip);

                        ppp.setEncryptionKeyLength(keyLength);

                        document.protect(ppp);
                    }
                    else
                    {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

                if( !document.isEncrypted() )
                {
                    if( certFile != null )
                    {
                        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
                        PublicKeyRecipient recip = new PublicKeyRecipient();
                        recip.setPermission(ap);


                        CertificateFactory cf = CertificateFactory.getInstance("X.509");
                        InputStream inStream = new FileInputStream(certFile);
                        X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
                        inStream.close();

                        recip.setX509(certificate);

                        ppp.addRecipient(recip);

                        ppp.setEncryptionKeyLength(keyLength);

                        document.protect(ppp);
                    }
                    else
                    {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an unexpected error during the test.
     */
    public void testProtectionError() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        document.protect(policy);

        PDDocument encrypted = reload(document);
        try
        {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an unexpected error during the test.
     */
    public void testProtection() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        document.protect(policy);

        PDDocument encrypted = reload(document);
        try
        {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

     *
     * @throws Exception If there is an error during the test.
     */
    public void testMultipleRecipients() throws Exception
    {
        PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
        policy.addRecipient(recipient1);
        policy.addRecipient(recipient2);
        document.protect(policy);

        // open first time
        PDDocument encrypted1 = reload(document);
        try
View Full Code Here

Examples of org.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy

       
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
       
        PDDocument doc = PDDocument.load(input);
       
        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
       
        PublicKeyRecipient recip1 = new PublicKeyRecipient();
        PublicKeyRecipient recip2 = new PublicKeyRecipient();
       
        recip1.setPermission(accessPermission);
        recip2.setPermission(accessPermission2);
       
        InputStream inStream = new FileInputStream(publicCert1);       
        Assert.assertNotNull(cf);
        X509Certificate certificate1 = (X509Certificate)cf.generateCertificate(inStream);
        inStream.close();       
       
        InputStream inStream2 = new FileInputStream(publicCert2);       
        Assert.assertNotNull(cf);
        X509Certificate certificate2 = (X509Certificate)cf.generateCertificate(inStream2);
        inStream.close();       
       
        recip1.setX509(certificate1);
        recip2.setX509(certificate2);
       
        ppp.addRecipient(recip1);
        ppp.addRecipient(recip2);
       
        doc.protect(ppp);               
        doc.save(output.getAbsolutePath());       
        doc.close();
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.