org.apache.pdfbox.pdmodel.encryption
public class: PublicKeyProtectionPolicy [javadoc |
source]
java.lang.Object
org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy
org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy
This class represents the protection policy to use to protect
a document with the public key security handler as described
in the PDF specification 1.6 p104.
PDF documents are encrypted so that they can be decrypted by
one or more recipients. Each recipient have its own access permission.
The following code sample shows how to protect a document using
the public key security handler. In this code sample,
doc
is
a
PDDocument
object.
PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy();
PublicKeyRecipient recip = new PublicKeyRecipient();
AccessPermission ap = new AccessPermission();
ap.setCanModify(false);
recip.setPermission(ap);
// load the recipient's certificate
InputStream inStream = new FileInputStream(certificate_path);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
inStream.close();
recip.setX509(certificate); // set the recipient's certificate
policy.addRecipient(recip);
policy.setEncryptionKeyLength(128); // the document will be encrypted with 128 bits secret key
doc.protect(policy);
doc.save(out);
Also see:
- org.apache.pdfbox.pdmodel.PDDocument#protect(ProtectionPolicy)
- AccessPermission
- PublicKeyRecipient
- author:
Benoit
- Guillon (benoit.guillon@snv.jussieu.fr)
- version:
$
- Revision: 1.2 $
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |