org.apache.pdfbox.pdmodel.encryption

## Class PublicKeySecurityHandler

- java.lang.Object
- - org.apache.pdfbox.pdmodel.encryption.SecurityHandler
  - - org.apache.pdfbox.pdmodel.encryption.PublicKeySecurityHandler

    public final class PublicKeySecurityHandler
    extends SecurityHandler

This class implements the public key security handler described in the PDF specification.

Author:
  Benoit Guillon
See Also:
  `to see how to protect document with this security handler.`

### Field Summary

Fields
`static String` `FILTER` The filter name.

### Fields inherited from class org.apache.pdfbox.pdmodel.encryption.SecurityHandler

`encryptionKey, keyLength`

### Constructor Summary

Constructors
Constructor and Description
`PublicKeySecurityHandler()` Constructor.
`PublicKeySecurityHandler(PublicKeyProtectionPolicy publicKeyProtectionPolicy)` Constructor used for encryption.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `prepareDocumentForEncryption(PDDocument doc)` Prepare the document for encryption.
`void` `prepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial)` Prepares everything to decrypt the document.

### Methods inherited from class org.apache.pdfbox.pdmodel.encryption.SecurityHandler

`computeVersionNumber, decrypt, decryptStream, encryptDataRC4, encryptDataRC4, encryptStream, encryptString, getCurrentAccessPermission, getEncryptionKey, getKeyLength, getProtectionPolicy, hasProtectionPolicy, isAES, isDecryptMetadata, setAES, setCurrentAccessPermission, setCustomSecureRandom, setDecryptMetadata, setEncryptionKey, setKeyLength, setProtectionPolicy, setStreamFilterName, setStringFilterName`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### FILTER

    public static final String FILTER

The filter name.

See Also:
  Constant Field Values

### Constructor Detail

#### PublicKeySecurityHandler

    public PublicKeySecurityHandler()

Constructor.

#### PublicKeySecurityHandler

    public PublicKeySecurityHandler(PublicKeyProtectionPolicy publicKeyProtectionPolicy)

Constructor used for encryption.

Parameters:
  `publicKeyProtectionPolicy` - The protection policy.

### Method Detail

#### prepareForDecryption

    public void prepareForDecryption(PDEncryption encryption,
                                     COSArray documentIDArray,
                                     DecryptionMaterial decryptionMaterial)
                              throws IOException

Prepares everything to decrypt the document.

Specified by:
  `prepareForDecryption` in class `SecurityHandler`
Parameters:
  `encryption` - encryption dictionary, can be retrieved via `PDDocument.getEncryption()`
  `documentIDArray` - document id which is returned via `COSDocument.getDocumentID()` (not used by this handler)
  `decryptionMaterial` - Information used to decrypt the document.
Throws:
  `IOException` - If there is an error accessing data. If verbose mode is enabled, the exception message will provide more details why the match wasn't successful.

#### prepareDocumentForEncryption

    public void prepareDocumentForEncryption(PDDocument doc)
                                      throws IOException

Prepare the document for encryption.

Specified by:
  `prepareDocumentForEncryption` in class `SecurityHandler`
Parameters:
  `doc` - The document that will be encrypted.
Throws:
  `IOException` - If there is an error while encrypting.