java 解密PDF格式文件

importjava.io.FileOutputStream;

importcom.lowagie.text.pdf.PdfEncryptor;
importcom.lowagie.text.pdf.PdfReader;
importcom.lowagie.text.pdf.PdfStamper;
importcom.lowagie.text.pdf.PdfWriter;

publicclassMainClass{

publicstaticvoidmain(String[]args)throwsException{
PdfEncryptor
.encrypt(newPdfReader("1.pdf"),newFileOutputStream("Encrypted2.pdf"),
"Hello".getBytes(),"World".getBytes(),PdfWriter.AllowDegradedPrinting,
PdfWriter.STRENGTH128BITS);

//decryptthefile

PdfReaderreader=newPdfReader("Encrypted2.pdf","World".getBytes());
PdfStamperstamper=newPdfStamper(reader,newFileOutputStream("Decrypted1.pdf"));
stamper.close();

getEncryptionInformation("1.pdf",null);
getEncryptionInformation("Encrypted2.pdf","World");
getEncryptionInformation("Decrypted1.pdf","World");
}

publicstaticvoidgetEncryptionInformation(Stringfilename,Stringownerpassword)
throwsException{
PdfReaderreader;
if(ownerpassword==null)
reader=newPdfReader(filename);
else
reader=newPdfReader(filename,ownerpassword.getBytes());
System.out.println("Encrypted?"+reader.isEncrypted());
if(reader.isEncrypted()){
System.out.println("Permissions:"
+PdfEncryptor.getPermissionsVerbose(reader.getPermissions()));
System.out.println("128bit?"+reader.is128Key());
}
}

}

你可能感兴趣的:(java)