public abstract class SecurityHandler extends Object
Modifier and Type | Field and Description |
---|---|
protected AccessPermission |
currentAccessPermission
The access permission granted to the current user for the document.
|
protected boolean |
decryptMetadata
indicates if the Metadata have to be decrypted of not
|
protected PDDocument |
document
The document whose security is handled by this security handler.
|
protected byte[] |
encryptionKey
The encryption key that will used to encrypt / decrypt.
|
protected int |
keyLength
The length of the secret key used to encrypt the document.
|
protected ARCFour |
rc4
The RC4 implementation used for cryptographic functions.
|
protected int |
version
The value of V field of the Encryption dictionary.
|
Constructor and Description |
---|
SecurityHandler() |
Modifier and Type | Method and Description |
---|---|
void |
decryptArray(COSArray array,
long objNum,
long genNum)
This will decrypt an array.
|
abstract void |
decryptDocument(PDDocument doc,
DecryptionMaterial mat)
Prepare the document for decryption.
|
void |
decryptStream(COSStream stream,
long objNum,
long genNum)
This will decrypt a stream.
|
void |
decryptString(COSString string,
long objNum,
long genNum)
This will decrypt a string.
|
void |
encryptData(long objectNumber,
long genNumber,
InputStream data,
OutputStream output)
Deprecated.
While this works fine for RC4 encryption, it will never decrypt AES data You should use
encryptData(objectNumber, genNumber, data, output, decrypt) which can do everything. This function is
just here for compatibility reasons and will be removed in the future.
|
void |
encryptData(long objectNumber,
long genNumber,
InputStream data,
OutputStream output,
boolean decrypt)
Encrypt a set of data.
|
void |
encryptStream(COSStream stream,
long objNum,
long 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,
long genNum)
This will encrypt a string.
|
AccessPermission |
getCurrentAccessPermission()
Returns the access permissions that were computed during document decryption.
|
int |
getKeyLength()
Getter of the property keyLength.
|
abstract boolean |
hasProtectionPolicy()
Returns whether a protection policy has been set.
|
boolean |
isAES()
True if AES is used for encryption and decryption.
|
abstract void |
prepareDocumentForEncryption(PDDocument doc)
Prepare the document for encryption.
|
abstract void |
prepareForDecryption(PDEncryptionDictionary encDictionary,
COSArray documentIDArray,
DecryptionMaterial decryptionMaterial)
Prepares everything to decrypt the document.
|
protected void |
proceedDecryption()
This method must be called by an implementation of this class to really proceed to decryption.
|
void |
setAES(boolean aesValue)
Set to true if AES for encryption and decryption should be used.
|
void |
setKeyLength(int keyLen)
Setter of the property keyLength.
|
protected int version
protected int keyLength
protected byte[] encryptionKey
protected PDDocument document
protected ARCFour rc4
protected boolean decryptMetadata
protected AccessPermission currentAccessPermission
public abstract void prepareDocumentForEncryption(PDDocument doc) throws CryptographyException, IOException
doc
- The document that will be encrypted.CryptographyException
- If there is an error while preparing.IOException
- If there is an error with the document.public abstract void prepareForDecryption(PDEncryptionDictionary encDictionary, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) throws CryptographyException, IOException
decryptDocument(PDDocument, DecryptionMaterial)
is used, this method is called from there. Only if
decryption of single objects is needed this should be called instead.encDictionary
- encryption dictionary, can be retrieved via PDDocument.getEncryptionDictionary()
documentIDArray
- document id which is returned via COSDocument.getDocumentID()
decryptionMaterial
- Information used to decrypt the document.IOException
- If there is an error accessing data.CryptographyException
- If there is an error with decryption.public abstract void decryptDocument(PDDocument doc, DecryptionMaterial mat) throws CryptographyException, IOException
doc
- The document to decrypt.mat
- Information required to decrypt the document.CryptographyException
- If there is an error while preparing.IOException
- If there is an error with the document.protected void proceedDecryption() throws IOException, CryptographyException
IOException
- If there is an error in the decryption.CryptographyException
- If there is an error in the decryption.public void encryptData(long objectNumber, long genNumber, InputStream data, OutputStream output) throws CryptographyException, IOException
objectNumber
- The data object number.genNumber
- The data generation number.data
- The data to encrypt.output
- The output to write the encrypted data to.CryptographyException
- If there is an error during the encryption.IOException
- If there is an error reading the data.public void encryptData(long objectNumber, long genNumber, InputStream data, OutputStream output, boolean decrypt) throws CryptographyException, IOException
objectNumber
- The data object number.genNumber
- The data generation number.data
- The data to encrypt.output
- The output to write the encrypted data to.decrypt
- true to decrypt the data, false to encrypt itCryptographyException
- If there is an error during the encryption.IOException
- If there is an error reading the data.public void decryptStream(COSStream stream, long objNum, long genNum) throws CryptographyException, IOException
stream
- The stream to decrypt.objNum
- The object number.genNum
- The object generation number.CryptographyException
- If there is an error getting the stream.IOException
- If there is an error getting the stream data.public void encryptStream(COSStream stream, long objNum, long genNum) throws CryptographyException, IOException
stream
- The stream to decrypt.objNum
- The object number.genNum
- The object generation number.CryptographyException
- If there is an error getting the stream.IOException
- If there is an error getting the stream data.public void encryptString(COSString string, long objNum, long genNum) throws CryptographyException, IOException
string
- the string to encrypt.objNum
- The object number.genNum
- The object generation number.IOException
- If an error occurs writing the new string.CryptographyException
public void decryptString(COSString string, long objNum, long genNum) throws CryptographyException, IOException
string
- the string to decrypt.objNum
- The object number.genNum
- The object generation number.CryptographyException
- If an error occurs during decryption.IOException
- If an error occurs writing the new string.public void decryptArray(COSArray array, long objNum, long genNum) throws CryptographyException, IOException
array
- The array to decrypt.objNum
- The object number.genNum
- The object generation number.CryptographyException
- If an error occurs during decryption.IOException
- If there is an error accessing the data.public int getKeyLength()
public void setKeyLength(int keyLen)
keyLen
- The keyLength to set.public AccessPermission getCurrentAccessPermission()
public boolean isAES()
public void setAES(boolean aesValue)
aesValue
- if true AES will be usedpublic abstract boolean hasProtectionPolicy()
Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.