T_POLICY
- the protection policy.public abstract class SecurityHandler<T_POLICY extends ProtectionPolicy> extends Object
Modifier | Constructor and Description |
---|---|
protected |
SecurityHandler()
Constructor.
|
protected |
SecurityHandler(T_POLICY protectionPolicy)
Constructor used for encryption.
|
Modifier and Type | Method and Description |
---|---|
protected int |
computeVersionNumber()
Computes the version number of the
SecurityHandler based on the encryption key
length. |
void |
decrypt(COSBase obj,
long objNum,
long genNum)
This will dispatch to the correct method.
|
void |
decryptStream(COSStream stream,
long objNum,
long genNum)
This will decrypt a stream.
|
protected void |
encryptDataRC4(byte[] finalKey,
byte[] input,
OutputStream output)
Encrypt or decrypt data with RC4.
|
protected void |
encryptDataRC4(byte[] finalKey,
InputStream input,
OutputStream output)
Encrypt or decrypt data with RC4.
|
void |
encryptStream(COSStream stream,
long objNum,
int genNum)
This will encrypt a stream, but not the dictionary as the dictionary is
encrypted by visitFromString() in COSWriter and we don't want to encrypt
it twice.
|
void |
encryptString(COSString string,
long objNum,
int genNum)
This will encrypt a string.
|
AccessPermission |
getCurrentAccessPermission()
Returns the access permissions that were computed during document decryption.
|
byte[] |
getEncryptionKey()
Returns the current encryption key data.
|
int |
getKeyLength()
Getter of the property keyLength.
|
protected T_POLICY |
getProtectionPolicy()
Returns the set
ProtectionPolicy or null. |
boolean |
hasProtectionPolicy()
Returns whether a protection policy has been set.
|
boolean |
isAES()
True if AES is used for encryption and decryption.
|
boolean |
isDecryptMetadata()
Returns true if meta data is to be decrypted.
|
abstract void |
prepareDocumentForEncryption(PDDocument doc)
Prepare the document for encryption.
|
abstract void |
prepareForDecryption(PDEncryption encryption,
COSArray documentIDArray,
DecryptionMaterial decryptionMaterial)
Prepares everything to decrypt the document.
|
void |
setAES(boolean aesValue)
Set to true if AES for encryption and decryption should be used.
|
void |
setCurrentAccessPermission(AccessPermission currentAccessPermission)
Sets the access permissions.
|
void |
setCustomSecureRandom(SecureRandom customSecureRandom)
Set the custom SecureRandom.
|
protected void |
setDecryptMetadata(boolean decryptMetadata)
Set whether to decrypt meta data.
|
void |
setEncryptionKey(byte[] encryptionKey)
Sets the current encryption key data.
|
void |
setKeyLength(int keyLen)
Setter of the property keyLength.
|
protected void |
setProtectionPolicy(T_POLICY protectionPolicy)
Sets the
ProtectionPolicy to the given value. |
protected void |
setStreamFilterName(COSName streamFilterName)
Set the stream filter name.
|
protected void |
setStringFilterName(COSName stringFilterName)
Set the string filter name.
|
protected SecurityHandler()
protected SecurityHandler(T_POLICY protectionPolicy)
protectionPolicy
- The protection policy.protected void setDecryptMetadata(boolean decryptMetadata)
decryptMetadata
- true if meta data has to be decrypted.public boolean isDecryptMetadata()
protected void setStringFilterName(COSName stringFilterName)
stringFilterName
- the string filter name.protected void setStreamFilterName(COSName streamFilterName)
streamFilterName
- the stream filter name.public void setCustomSecureRandom(SecureRandom customSecureRandom)
customSecureRandom
- the custom SecureRandom for AES encryptionpublic abstract void prepareDocumentForEncryption(PDDocument doc) throws IOException
doc
- The document that will be encrypted.IOException
- If there is an error with the document.public abstract void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) throws IOException
encryption
- encryption dictionary, can be retrieved via PDDocument.getEncryption()
documentIDArray
- document id which is returned via COSDocument.getDocumentID()
decryptionMaterial
- Information used to decrypt the document.InvalidPasswordException
- If the password is incorrect.IOException
- If there is an error accessing data.protected void encryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException
finalKey
- The final key obtained with via calcFinalKey(long, long)
.input
- The data to encrypt.output
- The output to write the encrypted data to.IOException
- If there is an error reading the data.protected void encryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException
finalKey
- The final key obtained with via calcFinalKey(long, long)
.input
- The data to encrypt.output
- The output to write the encrypted data to.IOException
- If there is an error reading the data.public void decrypt(COSBase obj, long objNum, long genNum) throws IOException
obj
- The object to decrypt.objNum
- The object number.genNum
- The object generation Number.IOException
- If there is an error getting the stream data.public void decryptStream(COSStream stream, long objNum, long genNum) throws IOException
stream
- The stream to decrypt.objNum
- The object number.genNum
- The object generation number.IOException
- If there is an error getting the stream data.public void encryptStream(COSStream stream, long objNum, int genNum) throws IOException
stream
- The stream to decrypt.objNum
- The object number.genNum
- The object generation number.IOException
- If there is an error getting the stream data.public void encryptString(COSString string, long objNum, int genNum) throws IOException
string
- the string to encrypt.objNum
- The object number.genNum
- The object generation number.IOException
- If an error occurs writing the new string.public int getKeyLength()
public void setKeyLength(int keyLen)
keyLen
- The keyLength to set.public void setCurrentAccessPermission(AccessPermission currentAccessPermission)
currentAccessPermission
- The access permissions to be set.public AccessPermission getCurrentAccessPermission()
public boolean isAES()
public void setAES(boolean aesValue)
aesValue
- if true AES will be usedpublic boolean hasProtectionPolicy()
protected T_POLICY getProtectionPolicy()
ProtectionPolicy
or null.ProtectionPolicy
.protected void setProtectionPolicy(T_POLICY protectionPolicy)
ProtectionPolicy
to the given value.protectionPolicy
- The ProtectionPolicy
, that shall be set.public byte[] getEncryptionKey()
public void setEncryptionKey(byte[] encryptionKey)
encryptionKey
- The encryption key data to set.protected int computeVersionNumber()
SecurityHandler
based on the encryption key
length. See PDF Spec 1.6 p 93 and
PDF
1.7 Supplement ExtensionLevel: 3 and
PDF
Spec 2.0.Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.