public class StandardSecurityHandler extends SecurityHandler
to see how to protect document with this security handler.
Modifier and Type | Field and Description |
---|---|
static byte[] |
ENCRYPT_PADDING
Standard padding for encryption.
|
static java.lang.String |
FILTER
Type of security handler.
|
static java.lang.Class |
PROTECTION_POLICY_CLASS
Protection policy class for this handler.
|
currentAccessPermission, document, encryptionKey, keyLength, version
Constructor and Description |
---|
StandardSecurityHandler()
Constructor.
|
StandardSecurityHandler(StandardProtectionPolicy p)
Constructor used for encryption.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
computeEncryptedKey(byte[] password,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
Compute the encryption key.
|
byte[] |
computeOwnerPassword(byte[] ownerPassword,
byte[] userPassword,
int encRevision,
int length)
Compute the owner entry in the encryption dictionary.
|
byte[] |
computeUserPassword(byte[] password,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
This will compute the user password hash.
|
void |
decryptDocument(PDDocument doc,
DecryptionMaterial decryptionMaterial)
Decrypt the document.
|
byte[] |
getUserPassword(byte[] ownerPassword,
byte[] o,
int encRevision,
long length)
Get the user password based on the owner password.
|
boolean |
isOwnerPassword(byte[] ownerPassword,
byte[] u,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
Check for owner password.
|
boolean |
isOwnerPassword(java.lang.String password,
byte[] u,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
Check for owner password.
|
boolean |
isUserPassword(byte[] password,
byte[] u,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
Check if a plaintext password is the user password.
|
boolean |
isUserPassword(java.lang.String password,
byte[] u,
byte[] o,
int permissions,
byte[] id,
int encRevision,
int length,
boolean encryptMetadata)
Check if a plaintext password is the user password.
|
void |
prepareDocumentForEncryption(PDDocument doc)
Prepare document for encryption.
|
decryptStream, decryptString, encryptData, encryptData, encryptStream, getCurrentAccessPermission, getKeyLength, isAES, proceedDecryption, setAES, setKeyLength
public static final java.lang.String FILTER
public static final java.lang.Class PROTECTION_POLICY_CLASS
public static final byte[] ENCRYPT_PADDING
public StandardSecurityHandler()
public StandardSecurityHandler(StandardProtectionPolicy p)
p
- The protection policy.public void decryptDocument(PDDocument doc, DecryptionMaterial decryptionMaterial) throws CryptographyException, java.io.IOException
decryptDocument
in class SecurityHandler
doc
- The document to be decrypted.decryptionMaterial
- Information used to decrypt the document.java.io.IOException
- If there is an error accessing data.CryptographyException
- If there is an error with decryption.public void prepareDocumentForEncryption(PDDocument doc) throws CryptographyException, java.io.IOException
prepareDocumentForEncryption
in class SecurityHandler
doc
- The documeent to encrypt.java.io.IOException
- If there is an error accessing data.CryptographyException
- If there is an error with decryption.public final boolean isOwnerPassword(byte[] ownerPassword, byte[] u, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException, java.io.IOException
ownerPassword
- The owner password.u
- The u entry of the encryption dictionary.o
- The o entry of the encryption dictionary.permissions
- The set of permissions on the document.id
- The document id.encRevision
- The encryption algorithm revision.length
- The encryption key length.CryptographyException
- If there is an error during encryption.java.io.IOException
- If there is an error accessing data.public final byte[] getUserPassword(byte[] ownerPassword, byte[] o, int encRevision, long length) throws CryptographyException, java.io.IOException
ownerPassword
- The plaintext owner password.o
- The o entry of the encryption dictionary.encRevision
- The encryption revision number.length
- The key length.CryptographyException
- If there is an error generating the user password.java.io.IOException
- If there is an error accessing data while generating the user password.public final byte[] computeEncryptedKey(byte[] password, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException
password
- The password to compute the encrypted key.o
- The o entry of the encryption dictionary.permissions
- The permissions for the document.id
- The document id.encRevision
- The revision of the encryption algorithm.length
- The length of the encryption key.CryptographyException
- If there is an error with encryption.public final byte[] computeUserPassword(byte[] password, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException, java.io.IOException
password
- The plain text password.o
- The owner password hash.permissions
- The document permissions.id
- The document id.encRevision
- The revision of the encryption.length
- The length of the encryption key.CryptographyException
- If there is an error computing the user password.java.io.IOException
- If there is an IO error.public final byte[] computeOwnerPassword(byte[] ownerPassword, byte[] userPassword, int encRevision, int length) throws CryptographyException, java.io.IOException
ownerPassword
- The plaintext owner password.userPassword
- The plaintext user password.encRevision
- The revision number of the encryption algorithm.length
- The length of the encryption key.CryptographyException
- If there is an error with encryption.java.io.IOException
- If there is an error accessing data.public final boolean isUserPassword(byte[] password, byte[] u, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException, java.io.IOException
password
- The plaintext password.u
- The u entry of the encryption dictionary.o
- The o entry of the encryption dictionary.permissions
- The permissions set in the the PDF.id
- The document id used for encryption.encRevision
- The revision of the encryption algorithm.length
- The length of the encryption key.CryptographyException
- If there is an error during encryption.java.io.IOException
- If there is an error accessing data.public final boolean isUserPassword(java.lang.String password, byte[] u, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException, java.io.IOException
password
- The plaintext password.u
- The u entry of the encryption dictionary.o
- The o entry of the encryption dictionary.permissions
- The permissions set in the the PDF.id
- The document id used for encryption.encRevision
- The revision of the encryption algorithm.length
- The length of the encryption key.CryptographyException
- If there is an error during encryption.java.io.IOException
- If there is an error accessing data.public final boolean isOwnerPassword(java.lang.String password, byte[] u, byte[] o, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws CryptographyException, java.io.IOException
password
- The owner password.u
- The u entry of the encryption dictionary.o
- The o entry of the encryption dictionary.permissions
- The set of permissions on the document.id
- The document id.encRevision
- The encryption algorithm revision.length
- The encryption key length.CryptographyException
- If there is an error during encryption.java.io.IOException
- If there is an error accessing data.