public final class PublicKeyProtectionPolicy extends ProtectionPolicy
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);
PDDocument.protect(ProtectionPolicy),
AccessPermission,
PublicKeyRecipient| Constructor | Description |
|---|---|
PublicKeyProtectionPolicy() |
Creates a new PublicKeyProtectionPolicy with an empty recipients list.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addRecipient(PublicKeyRecipient recipient) |
Adds a new recipient to the recipients list.
|
java.security.cert.X509Certificate |
getDecryptionCertificate() |
Returns the decryption certificate.
|
int |
getNumberOfRecipients() |
Returns the number of recipients
|
java.util.Iterator<PublicKeyRecipient> |
getRecipientsIterator() |
Returns an iterator to browse the list of recipients.
|
boolean |
removeRecipient(PublicKeyRecipient recipient) |
Removes a recipient from the recipients list.
|
void |
setDecryptionCertificate(java.security.cert.X509Certificate decryptionCertificate) |
Sets the decryption certificate
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetEncryptionKeyLength, setEncryptionKeyLengthpublic PublicKeyProtectionPolicy()
public void addRecipient(PublicKeyRecipient recipient)
recipient - A new recipient.public boolean removeRecipient(PublicKeyRecipient recipient)
recipient - The recipient to remove.public java.util.Iterator<PublicKeyRecipient> getRecipientsIterator()
PublicKeyRecipient.public java.security.cert.X509Certificate getDecryptionCertificate()
public void setDecryptionCertificate(java.security.cert.X509Certificate decryptionCertificate)
decryptionCertificate - the new decryption certificate.public int getNumberOfRecipients()
Copyright © 2002–2018. All rights reserved.