public class

SecurityHandler

extends Object
implements Cloneable
java.lang.Object
   ↳ com.pdftron.sdf.SecurityHandler

Class Overview

Standard Security Handler is a built-in password-based security handler.

Summary

Constants
int e_AES Use Crypt filters with 128-bit AES (Advanced Encryption Standard) algorithm.
int e_AES_256 Use Crypt filters with 256-bit AES (Advanced Encryption Standard) algorithm.
int e_RC4_128 128-bit RC4 algorithm.
int e_RC4_40 The algorithm Constants to be used in encrypting and decrypting the document.
int e_access_support The Constant e_access_support.
int e_assemble_doc The Constant e_assemble_doc.
int e_doc_modify The Constant e_doc_modify.
int e_doc_open The Constant e_doc_open.
int e_extract_content The Constant e_extract_content.
int e_fill_forms The Constant e_fill_forms.
int e_mod_annot The Constant e_mod_annot.
int e_owner The Constant e_owner.
int e_print The Constant e_print.
int e_print_high The Constant e_print_high.
Public Constructors
SecurityHandler(int crypt_type)
Create a Standard Security Handler.
SecurityHandler(int key_len, int enc_code)
Create a Standard Security Handler.
SecurityHandler()
Instantiates a new security handler.
Public Methods
static SecurityHandler __Create(long impl, Object ref)
long __GetHandle()
void __SetRefHandle(Object ref)
void changeMasterPassword(byte[] passwordBuffer)
Modify the master/owner password.
void changeMasterPassword(String password)
Modify the master password.
void changeRevisionNumber(int rev_num)
Change the revision number and the encryption algorithm of the standard security handler.
void changeUserPassword(byte[] passwordBuffer)
Modify the user password.
void changeUserPassword(String password)
Modify the user password.
Object clone()
void destroy()
Frees the native memory of the object.
int getEncryptionAlgorithmID()
Get the encryption algorithm ID.
String getHandlerDocName()
Get the name of SecurityHandler.
int getKeyLength()
Get the encryption key length.
String getMasterPassword()
Get the master password.
boolean getPermission(int type)
Get the security permission.
int getRevisionNumber()
Get the revision number.
String getUserPassword()
Get the user password.
boolean isAES()
Checks if encryption is AES.
boolean isAES(Obj stream)
The following function can be used to verify whether a given stream is encrypted using AES.
boolean isMasterPasswordRequired()
Checks if is master password required.
boolean isModified()
Checks if SecurityHandler is modified.
boolean isRC4()
Checks if encryption is RC4.
boolean isUserPasswordRequired()
Checks if is user password required.
void setEncryptMetadata(boolean encrypt_metadata)
Indicates whether the document-level metadata stream is to be encrypted.
void setModified()
The method allows derived classes to set SecurityHandler is modified flag.
void setModified(boolean is_modified)
The method allows derived classes to set SecurityHandler is modified flag.
void setPermission(int perm, boolean value)
Set the permission setting of the StdSecurityHandler.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int e_AES

Use Crypt filters with 128-bit AES (Advanced Encryption Standard) algorithm.

Constant Value: 3 (0x00000003)

public static final int e_AES_256

Use Crypt filters with 256-bit AES (Advanced Encryption Standard) algorithm.

Constant Value: 4 (0x00000004)

public static final int e_RC4_128

128-bit RC4 algorithm.

Constant Value: 2 (0x00000002)

public static final int e_RC4_40

The algorithm Constants to be used in encrypting and decrypting the document. 40-bit RC4 algorithm.

Constant Value: 1 (0x00000001)

public static final int e_access_support

The Constant e_access_support.

Constant Value: 9 (0x00000009)

public static final int e_assemble_doc

The Constant e_assemble_doc.

Constant Value: 10 (0x0000000a)

public static final int e_doc_modify

The Constant e_doc_modify.

Constant Value: 3 (0x00000003)

public static final int e_doc_open

The Constant e_doc_open.

Constant Value: 2 (0x00000002)

public static final int e_extract_content

The Constant e_extract_content.

Constant Value: 6 (0x00000006)

public static final int e_fill_forms

The Constant e_fill_forms.

Constant Value: 8 (0x00000008)

public static final int e_mod_annot

The Constant e_mod_annot.

Constant Value: 7 (0x00000007)

public static final int e_owner

The Constant e_owner.

Constant Value: 1 (0x00000001)

public static final int e_print

The Constant e_print.

Constant Value: 4 (0x00000004)

public static final int e_print_high

The Constant e_print_high.

Constant Value: 5 (0x00000005)

Public Constructors

public SecurityHandler (int crypt_type)

Create a Standard Security Handler.

Parameters
crypt_type The encryption algorithm identifier.

public SecurityHandler (int key_len, int enc_code)

Create a Standard Security Handler.

Parameters
key_len The bit length of the encryption key (40 or 128 bit). Default value is 128.
enc_code The encryption algorithm identifier. The number corresponds to the V entry in encryption dictionary. Currently allowed values are (see Table 3.18 in PDF Reference Manual v1.6 for more details):
  • 1: Encryption using 40-bit RC4 algorithm.
  • 2: Encryption using 128-bit RC4 algorithm. Available in PDF 1.4 and above.
  • 3: This algorithm was deprecated by PDF standard and is not supported.
  • 4: Encryption using Crypt filters and 128-bit AES (Advanced Encryption Standard) algorithm. Available in PDF 1.6 and above.
Default value is 2.

public SecurityHandler ()

Instantiates a new security handler.

Public Methods

public static SecurityHandler __Create (long impl, Object ref)

public long __GetHandle ()

public void __SetRefHandle (Object ref)

public void changeMasterPassword (byte[] passwordBuffer)

Modify the master/owner password.

Parameters
passwordBuffer The new master/owner password represented in bytes.

public void changeMasterPassword (String password)

Modify the master password.

Parameters
password the new master/owner password

public void changeRevisionNumber (int rev_num)

Change the revision number and the encryption algorithm of the standard security handler.

Parameters
rev_num the new revision number of the standard security algorithm. Currently allowed values for the revision number are (see Table 3.18 in PDF Reference Manual v1.6 for more details): - 2 : Encryption using 40-bit RC4 algorithm. - 3 : Encryption using 128-bit RC4 algorithm. Available in PDF 1.4 and above. - 4 : Encryption using Crypt filters and 128-bit AES (Advanced Encryption Standard) algorithm. Available in PDF 1.6 and above.

public void changeUserPassword (byte[] passwordBuffer)

Modify the user password.

Parameters
passwordBuffer The new user password represented in bytes.

public void changeUserPassword (String password)

Modify the user password.

Parameters
password the new user password

public Object clone ()

public void destroy ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public int getEncryptionAlgorithmID ()

Get the encryption algorithm ID.

Returns
  • The encryption algorithm identifier. A code specifying the algorithm to be used in encrypting and decrypting the document. Returned number corrsponds to V entry in encryption dictionary. Currently allowed values are from 0-4. See PDF Reference Manual for more details.

public String getHandlerDocName ()

Get the name of SecurityHandler.

Returns
  • The name of the security handler as it appears in the serialized file as the value of /Filter key in /Encrypt dictionary.

public int getKeyLength ()

Get the encryption key length.

Note: The returned key length is given in bytes.

Returns
  • The length of the encryption key in bytes.

public String getMasterPassword ()

Get the master password.

Returns
  • Current master password.

public boolean getPermission (int type)

Get the security permission.

Parameters
type security permission types
Returns
  • true if the SecurityHandler permits the specified action (Permission p) on the document, or false if the permission was not granted.

public int getRevisionNumber ()

Get the revision number.

Returns
  • the revision number of the standard security algorithm.

public String getUserPassword ()

Get the user password.

Returns
  • Current user password.

public boolean isAES ()

Checks if encryption is AES.

Returns
  • true is this security handler uses 128 bit AES (Advanced Encryption Standard) algorithm to encrypt strings or streams.

public boolean isAES (Obj stream)

The following function can be used to verify whether a given stream is encrypted using AES.

Parameters
stream A pointer to an SDF::Stream object
Returns
  • true if the given stream is encrypted using AES encryption.

public boolean isMasterPasswordRequired ()

Checks if is master password required.

Returns
  • true if the SecurityHandler requires a master (owner) password.

public boolean isModified ()

Checks if SecurityHandler is modified.

Returns
  • - true if the SecurityHandler was modified (by calling SetModified()) or false otherwise. If the user changes SecurityHandler's settings (e.g. by changing a password), IsModified() should return true.

public boolean isRC4 ()

Checks if encryption is RC4.

Returns
  • true is this security handler uses RC4 algorithm to encrypt strings or streams.

public boolean isUserPasswordRequired ()

Checks if is user password required.

Returns
  • true if the SecurityHandler requires a user password.

public void setEncryptMetadata (boolean encrypt_metadata)

Indicates whether the document-level metadata stream is to be encrypted.

Note: EncryptMetadata flag affects only Crypt filters available in PDF 1.5 (Acrobat 6) and later. By default, metadata stream will be encrypted.

Parameters
encrypt_metadata true if metadata stream should be encrypted, false otherwise.

public void setModified ()

The method allows derived classes to set SecurityHandler is modified flag. This method should be called whenever there are changes (e.g. a password change) to the SecurityHandler

public void setModified (boolean is_modified)

The method allows derived classes to set SecurityHandler is modified flag. This method should be called whenever there are changes (e.g. a password change) to the SecurityHandler

Parameters
is_modified boolean value of SecurityHandler modification state

public void setPermission (int perm, boolean value)

Set the permission setting of the StdSecurityHandler.

Parameters
perm indicates a permission to set or clear. It can be any of the following values: e_print // print the document. e_doc_modify // edit the document more than adding or modifying text notes. e_extract_content // enable content extraction e_mod_annot // allow modifications to annotations e_fill_forms // allow changes to fill in forms e_access_support // content access for the visually impaired. e_assemble_doc // allow document assembly e_print_high // high resolution print.
value true if the permission/s should be granted, false otherwise.