Hello,

i am currently working on a Proof-of-Concept to expose the encryption
functionality of iText as a web service for external consumption. As this
Web Service is supposed to run on a SAP Netweaver Application Server 7.0
which is still based on Java 1.4.2 i cant use the latest iText release :( -
i am using iText 2.1.7.

What i have done so far is, i have wrapped an EJB around the iText Libs and
exposed the encryption function as a web service. The code to encrypt a pdf
is:

/import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;

....

        public byte[] encrypt(byte[] pdf, byte[] pwd) {
                // TODO : Implement
                
                try {
                        PdfReader reader = new PdfReader(pdf);
                        ByteArrayOutputStream boas = new 
ByteArrayOutputStream();
                        try {
                                PdfStamper stamper = new PdfStamper(reader, 
boas);                      
                                stamper.setEncryption(pwd, pwd,
                                                PdfWriter.ALLOW_PRINTING, 
PdfWriter.ENCRYPTION_AES_128 |
PdfWriter.DO_NOT_ENCRYPT_METADATA);
                                stamper.close();
                                return boas.toByteArray();
                        } catch (DocumentException e) {
                                e.printStackTrace();
                        }                               
                } catch (IOException e) {
                        e.printStackTrace();
                }               
                
                
                return null;
        }/

Unfortunatelly this code doesnt encrypt the pdf at all. The returning pdf
stream has no pwd set at all.

Has anyone an idea what could be wrong with this code? Or is there an issue
with the encryption function of the iText release 2.1.7?


When i do the same on a newer release of the SAP Netweaver Application
Server (Version 7.3) - which got released recently (its Java 1.6 based) and
the latest iText release with the following code to encrypt it does work
just fine!

/import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
....
   public byte[] encryptPDF(byte[] pdf, byte[] pwd) {
        
        
        
        try {
                        PdfReader reader = new PdfReader(pdf);
                        
                        ByteArrayOutputStream boas = new 
ByteArrayOutputStream();
                        
                        try {
                                
                                
                                PdfStamper stamper = new PdfStamper(reader, 
boas);
                                
                            stamper.setEncryption(pwd, pwd,
                                PdfWriter.ALLOW_PRINTING, 
PdfWriter.ENCRYPTION_AES_128 |
PdfWriter.DO_NOT_ENCRYPT_METADATA);
                        
                        stamper.close();
                                
                                return boas.toByteArray();
                                
                        } catch (DocumentException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        
        
        return null;
        
    }/




--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/PDF-encryption-as-a-Web-Service-on-a-JDK-1-4-based-Application-Server-tp3677768p3677768.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to