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);
org.apache.pdfbox.pdmodel.PDDocument#protect(ProtectionPolicy) , AccessPermission, PublicKeyRecipient
| Modifier and Type | Field and Description |
|---|---|
| private X509Certificate | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addRecipient(PublicKeyRecipient
A new recipient. recipient)Adds a new recipient to the recipients list. |
| public X509Certificate | |
| public int | |
| public Iterator | Returns: The recipients list iterator.Returns an iterator to browse the list of recipients. |
| public boolean | Returns: true If a recipient was found and removed.The recipient to remove. recipient)Removes a recipient from the recipients list. |
| public void | setDecryptionCertificate(X509Certificate
the new decryption certificate. decryptionCertificate)Sets the decryption certificate |
| decryptionCertificate | back to summary |
|---|---|
| private X509Certificate decryptionCertificate | |
| recipients | back to summary |
|---|---|
| private final List<PublicKeyRecipient> recipients | |
| PublicKeyProtectionPolicy | back to summary |
|---|---|
| public PublicKeyProtectionPolicy() Creates a new PublicKeyProtectionPolicy with an empty recipients list. | |
| addRecipient | back to summary |
|---|---|
| public void addRecipient(PublicKeyRecipient recipient) Adds a new recipient to the recipients list.
| |
| getDecryptionCertificate | back to summary |
|---|---|
| public X509Certificate getDecryptionCertificate() Returns the decryption certificate.
| |
| getNumberOfRecipients | back to summary |
|---|---|
| public int getNumberOfRecipients() Returns the number of recipients
| |
| getRecipientsIterator | back to summary |
|---|---|
| public Iterator Returns an iterator to browse the list of recipients.
Object found in this iterator are
| |
| removeRecipient | back to summary |
|---|---|
| public boolean removeRecipient(PublicKeyRecipient recipient) Removes a recipient from the recipients list.
| |
| setDecryptionCertificate | back to summary |
|---|---|
| public void setDecryptionCertificate(X509Certificate decryptionCertificate) Sets the decryption certificate
| |