public 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 and Description |
---|
PublicKeyProtectionPolicy()
Constructor for encryption.
|
Modifier and Type | Method and Description |
---|---|
void |
addRecipient(PublicKeyRecipient r)
Adds a new recipient to the recipients list.
|
X509Certificate |
getDecryptionCertificate()
Getter of the property decryptionCertificate.
|
Iterator |
getRecipientsIterator()
Returns an iterator to browse the list of recipients.
|
int |
getRecipientsNumber()
Returns the number of recipients.
|
boolean |
removeRecipient(PublicKeyRecipient r)
Removes a recipient from the recipients list.
|
void |
setDecryptionCertificate(X509Certificate aDecryptionCertificate)
Setter of the property decryptionCertificate.
|
getEncryptionKeyLength, setEncryptionKeyLength
public PublicKeyProtectionPolicy()
public void addRecipient(PublicKeyRecipient r)
r
- A new recipient.public boolean removeRecipient(PublicKeyRecipient r)
r
- The recipient to remove.public Iterator getRecipientsIterator()
PublicKeyRecipient
.public X509Certificate getDecryptionCertificate()
public void setDecryptionCertificate(X509Certificate aDecryptionCertificate)
aDecryptionCertificate
- The decryption certificate to set.public int getRecipientsNumber()
Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.