Package org.verapdf.pd.encryption
Class StandardSecurityHandler
- java.lang.Object
-
- org.verapdf.pd.encryption.StandardSecurityHandler
-
public class StandardSecurityHandler extends Object
Class represents standard security handler. It authenticates user password and calculates encryption key for document.- Author:
- Sergey Shemyakov
-
-
Constructor Summary
Constructors Constructor Description StandardSecurityHandler(PDEncryption pdEncryption, COSObject id, COSDocument document)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanauthenticatePassword(String password)Checks if a given password is a user password to this PDF document and sets encryption key if password is successfully checked.booleancheckPassword()voiddecryptStream(COSStream stream, COSKey key)Applies decryption filter to the stream so it can be read as unencrypted.voiddecryptString(COSString string, COSKey stringKey)Decrypts string and writes result into string.byte[]getEncryptionKey()PDEncryptiongetPdEncryption()
-
-
-
Constructor Detail
-
StandardSecurityHandler
public StandardSecurityHandler(PDEncryption pdEncryption, COSObject id, COSDocument document)
Constructor.- Parameters:
pdEncryption- is encryption object of this PDF document.id- is ID object from document trailer.document- is COSDocument object associated with this security handler
-
-
Method Detail
-
authenticatePassword
public boolean authenticatePassword(String password)
Checks if a given password is a user password to this PDF document and sets encryption key if password is successfully checked.- Returns:
- true if a given password is a password to this PDF document.
-
getEncryptionKey
public byte[] getEncryptionKey()
- Returns:
- encryption key for this security handler. If password given by the user or empty string (if user's password is null) is not a valid password returns null.
-
checkPassword
public boolean checkPassword()
- Returns:
- true if the password given by the user or an empty string (if user's password is null) is a valid password for this PDF document.
-
decryptString
public void decryptString(COSString string, COSKey stringKey) throws IOException, GeneralSecurityException
Decrypts string and writes result into string.- Parameters:
string- is COSString to decrypt.stringKey- is COSKey of object that contains this COSString.- Throws:
IOExceptionGeneralSecurityException
-
decryptStream
public void decryptStream(COSStream stream, COSKey key) throws IOException, GeneralSecurityException
Applies decryption filter to the stream so it can be read as unencrypted.- Parameters:
stream- is COSStream with encrypted data.key- is COSKey of this stream.- Throws:
IOExceptionGeneralSecurityException
-
getPdEncryption
public PDEncryption getPdEncryption()
- Returns:
- PDEncryption of this security handler.
-
-