Package com.pd4ml.pdf.encryption
Class PublicKeyProtectionPolicy
- java.lang.Object
-
- com.pd4ml.pdf.encryption.ProtectionPolicy
-
- com.pd4ml.pdf.encryption.PublicKeyProtectionPolicy
-
public final class PublicKeyProtectionPolicy extends ProtectionPolicy
The protection policy to use to protect a document with the public key security handler. 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 aPDDocument
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);
- Author:
- Benoit Guillon
- See Also:
AccessPermission
,PublicKeyRecipient
-
-
Constructor Summary
Constructors Constructor Description PublicKeyProtectionPolicy()
Creates a new PublicKeyProtectionPolicy with an empty recipients list.
-
Method Summary
All Methods Instance Methods Concrete Methods 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 recipientsjava.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-
Methods inherited from class com.pd4ml.pdf.encryption.ProtectionPolicy
getEncryptionKeyLength, isPreferAES, setEncryptionKeyLength, setPreferAES
-
-
-
-
Method Detail
-
addRecipient
public void addRecipient(PublicKeyRecipient recipient)
Adds a new recipient to the recipients list.- Parameters:
recipient
- A new recipient.
-
removeRecipient
public boolean removeRecipient(PublicKeyRecipient recipient)
Removes a recipient from the recipients list.- Parameters:
recipient
- The recipient to remove.- Returns:
- true If a recipient was found and removed.
-
getRecipientsIterator
public java.util.Iterator<PublicKeyRecipient> getRecipientsIterator()
Returns an iterator to browse the list of recipients. Object found in this iterator arePublicKeyRecipient
.- Returns:
- The recipients list iterator.
-
getDecryptionCertificate
public java.security.cert.X509Certificate getDecryptionCertificate()
Returns the decryption certificate.- Returns:
- the decryption certificate
-
setDecryptionCertificate
public void setDecryptionCertificate(java.security.cert.X509Certificate decryptionCertificate)
Sets the decryption certificate- Parameters:
decryptionCertificate
- the new decryption certificate.
-
getNumberOfRecipients
public int getNumberOfRecipients()
Returns the number of recipients- Returns:
- the number of recipients
-
-