java.lang.Object
org.sejda.sambox.pdmodel.encryption.SecurityHandler
- Direct Known Subclasses:
PublicKeySecurityHandler,StandardSecurityHandler
A security handler as described in the PDF specifications. A security handler is responsible of
documents protection.
- Author:
- Ben Litchfield, Benoit Guillon, Manuel Kasper
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected shortThe length of the secret key used to encrypt the document. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis will dispatch to the correct method.protected voiddecryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) Encrypt or decrypt data with RC4.protected voiddecryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) Encrypt or decrypt data with RC4.voiddecryptStream(COSStream stream, long objNum, long genNum) This will decrypt a stream.Returns the access permissions that were computed during document decryption.byte[]intbooleanisAES()True if AES is used for encryption and decryption.booleanabstract voidprepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) Prepares everything to decrypt the document.voidsetAES(boolean aesValue) Set to true if AES for encryption and decryption should be used.voidsetCurrentAccessPermission(AccessPermission currentAccessPermission) protected voidsetDecryptMetadata(boolean decryptMetadata) Set wether to decrypt meta data.protected voidsetEncryptionKey(byte[] encryptionKey) voidsetKeyLength(int keyLen) protected voidsetStreamFilterName(COSName streamFilterName) Set the stream filter name.protected voidsetStringFilterName(COSName stringFilterName) Set the string filter name.
-
Field Details
-
keyLength
protected short keyLengthThe length of the secret key used to encrypt the document.
-
-
Constructor Details
-
SecurityHandler
public SecurityHandler()
-
-
Method Details
-
setDecryptMetadata
protected void setDecryptMetadata(boolean decryptMetadata) Set wether to decrypt meta data.- Parameters:
decryptMetadata- true if meta data has to be decrypted.
-
isDecryptMetadata
public boolean isDecryptMetadata()- Returns:
- True if meta data has to be decrypted.
-
setStringFilterName
Set the string filter name.- Parameters:
stringFilterName- the string filter name.
-
setStreamFilterName
Set the stream filter name.- Parameters:
streamFilterName- the stream filter name.
-
prepareForDecryption
public abstract void prepareForDecryption(PDEncryption encryption, COSArray documentIDArray, DecryptionMaterial decryptionMaterial) throws IOException Prepares everything to decrypt the document.- Parameters:
encryption- encryption dictionary, can be retrieved viaPDDocument.getEncryption()documentIDArray- document id which is returned viaCOSDocument.getDocumentID()decryptionMaterial- Information used to decrypt the document.- Throws:
IOException- If there is an error accessing data.
-
decryptDataRC4
protected void decryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException Encrypt or decrypt data with RC4.- Parameters:
finalKey- The final key obtained with viacalcFinalKey(long, long).input- The data to encrypt.output- The output to write the encrypted data to.- Throws:
IOException- If there is an error reading the data.
-
decryptDataRC4
protected void decryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException Encrypt or decrypt data with RC4.- Parameters:
finalKey- The final key obtained with viacalcFinalKey(long, long).input- The data to encrypt.output- The output to write the encrypted data to.- Throws:
IOException- If there is an error reading the data.
-
decrypt
This will dispatch to the correct method.- Parameters:
obj- The object to decrypt.objNum- The object number.genNum- The object generation Number.- Throws:
IOException- If there is an error getting the stream data.
-
decryptStream
This will decrypt a stream.- Parameters:
stream- The stream to decrypt.objNum- The object number.genNum- The object generation number.- Throws:
IOException- If there is an error getting the stream data.
-
getKeyLength
public int getKeyLength()- Returns:
- key length in bits
-
setKeyLength
public void setKeyLength(int keyLen) -
setCurrentAccessPermission
- Parameters:
currentAccessPermission- The access permissions to be set.
-
getCurrentAccessPermission
Returns the access permissions that were computed during document decryption. The returned object is in read only mode.- Returns:
- the access permissions or null if the document was not decrypted.
-
isAES
public boolean isAES()True if AES is used for encryption and decryption.- Returns:
- true if AEs is used
-
setAES
public void setAES(boolean aesValue) Set to true if AES for encryption and decryption should be used.- Parameters:
aesValue- if true AES will be used
-
getEncryptionKey
public byte[] getEncryptionKey() -
setEncryptionKey
protected void setEncryptionKey(byte[] encryptionKey)
-