Show / Hide Table of Contents

Class StdSecurityHandler

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

Inheritance
object
SecurityHandler
StdSecurityHandler
PDFTronCustomSecurityHandler
Implements
IDisposable
Inherited Members
SecurityHandler.Dispose(bool)
SecurityHandler.Dispose()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: pdftron.SDF
Assembly: PDFNet.dll
Syntax
public class StdSecurityHandler : SecurityHandler, IDisposable

Constructors

StdSecurityHandler()

Create a standard security handler from a given handler

Declaration
public StdSecurityHandler()

StdSecurityHandler(int, int)

Creates a standard security handler

Declaration
public StdSecurityHandler(int key_len, int enc_code)
Parameters
Type Name Description
int key_len

The bit length of the encryption key (40 or 128 bit).

int 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.

StdSecurityHandler(SecurityHandler)

Create a standard security handler from a given handler

Declaration
public StdSecurityHandler(SecurityHandler s)
Parameters
Type Name Description
SecurityHandler s

a SecurityHandler instance

StdSecurityHandler(StdSecurityHandler)

Declaration
public StdSecurityHandler(StdSecurityHandler s)
Parameters
Type Name Description
StdSecurityHandler s

StdSecurityHandler(AlgorithmType)

Create a standard security handler from a given handler

Declaration
public StdSecurityHandler(StdSecurityHandler.AlgorithmType type)
Parameters
Type Name Description
StdSecurityHandler.AlgorithmType type

type of encryption algorithm to use

Methods

Authorize(Permission)

The method is called when a user tries to set security for an encrypted document and when a user tries to open a file. It must decide, based on the contents of the authorization data structure, whether or not the user is permitted to open the file, and what permissions the user has for this file.

Declaration
public override bool Authorize(SecurityHandler.Permission req_opr)
Parameters
Type Name Description
SecurityHandler.Permission req_opr

permission to authorize

Returns
Type Description
bool
Overrides
SecurityHandler.Authorize(SecurityHandler.Permission)
Remarks

This callback must not obtain the authorization data by displaying a user interface into which a user can type a password). This is handled by the security handler's GetAuthorizationData(), which must be called before this callback. Instead, Authorize() should work with authorization data it has access to.

AuthorizeFailed()

A callback method indicating repeated failed authorization. Override this callback in order to provide a UI feedback for failed authorization. Default implementation returns immediately.

Declaration
public override void AuthorizeFailed()
Overrides
SecurityHandler.AuthorizeFailed()

ChangeMasterPassword(byte[])

Changes the master/owner password.

Declaration
public virtual void ChangeMasterPassword(byte[] passwordBuffer)
Parameters
Type Name Description
byte[] passwordBuffer

The new master/owner password.

ChangeMasterPassword(string)

Changes master password

Declaration
public virtual void ChangeMasterPassword(string password)
Parameters
Type Name Description
string password

new master password

ChangeRevisionNumber(int)

Changes revision number

Declaration
public virtual void ChangeRevisionNumber(int rev_num)
Parameters
Type Name Description
int rev_num

new revision number

ChangeUserPassword(byte[])

Changes the user password.

Declaration
public virtual void ChangeUserPassword(byte[] passwordBuffer)
Parameters
Type Name Description
byte[] passwordBuffer

The new user password.

ChangeUserPassword(string)

Changes user password

Declaration
public virtual void ChangeUserPassword(string password)
Parameters
Type Name Description
string password

new password

Clone()

Clones instance of SecurityHandler.

Declaration
public override SecurityHandler Clone()
Returns
Type Description
SecurityHandler

A new, cloned instance of SecurityHandler.

Overrides
SecurityHandler.Clone()
Remarks

this method must be implemented in any derived class from SecurityHandler.

EditSecurityData(SDFDoc)

Called when the security handler should activate a dialog box with the current security settings that may be modified.

Declaration
public override bool EditSecurityData(SDFDoc doc)
Parameters
Type Name Description
SDFDoc doc

document to change security data

Returns
Type Description
bool

true if the operation was successful false otherwise.

Overrides
SecurityHandler.EditSecurityData(SDFDoc)

FillEncryptDict(SDFDoc)

Called when an encrypted document is saved. Fills the document's Encryption dictionary with whatever information the security handler wants to store in the document.

  • encrypt_dict is created (if it does not exist)
  • Filter attribute is added to the dictionary
  • call this method to allow the security handler to add its own attributes
  • call the GetCryptKey to get the algorithm version, key, and key length
  • checks if the V attribute has been added to the dictionary and, if not, then sets V to the algorithm version
  • set the Length attribute if V is 2 or greater
  • add the encrypt_dict to the document
Declaration
public override Obj FillEncryptDict(SDFDoc doc)
Parameters
Type Name Description
SDFDoc doc

The document to save.

Returns
Type Description
Obj

encrypt_dict

Overrides
SecurityHandler.FillEncryptDict(SDFDoc)

GetAuthorizationData(Permission)

This method is invoked in case Authorize() failed.The callback must determine the user's authorization properties for the document by obtaining authorization data (e.g. a password through a GUI dialog).The authorization data is subsequently used by the security handler's Authorize() to determine whether or not the user is authorized to open the file.

Declaration
public override bool GetAuthorizationData(SecurityHandler.Permission req_opr)
Parameters
Type Name Description
SecurityHandler.Permission req_opr

the permission for which authorization data is requested.

Returns
Type Description
bool

false if the operation was canceled, true otherwise.

Overrides
SecurityHandler.GetAuthorizationData(SecurityHandler.Permission)

GetEncryptionAlgorithmID()

Gets encryption algorithm

Declaration
public override int GetEncryptionAlgorithmID()
Returns
Type Description
int

encryption algorithm

Overrides
SecurityHandler.GetEncryptionAlgorithmID()

GetHandlerDocName()

Gets the handler doc name.

Declaration
public override string GetHandlerDocName()
Returns
Type Description
string

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

Overrides
SecurityHandler.GetHandlerDocName()

GetKeyLength()

Gets key length

Declaration
public override int GetKeyLength()
Returns
Type Description
int

length of the encryption key

Overrides
SecurityHandler.GetKeyLength()

GetMasterPassword()

Gets master password

Declaration
public virtual string GetMasterPassword()
Returns
Type Description
string

master password

GetPermission(Permission)

Gets permission

Declaration
public override bool GetPermission(SecurityHandler.Permission p)
Parameters
Type Name Description
SecurityHandler.Permission p

A Permission to be granted.

Returns
Type Description
bool

true if the SecurityHandler permits the specified action p on the document, or false if the permission was not granted

Overrides
SecurityHandler.GetPermission(SecurityHandler.Permission)
Remarks

in order to check for permission the method will repeatedly (up to three times) attempt to GetAuthorizationData() and Authorize() permission. If the permission is not granted AuthorizeFailed() callback will be called. This callback method allows derived class to provide UI feedback for failed authorization.

GetRevisionNumber()

Gets revision number

Declaration
public virtual int GetRevisionNumber()
Returns
Type Description
int

revsion number

GetUserPassword()

Gets user password

Declaration
public virtual string GetUserPassword()
Returns
Type Description
string

user password

InitPassword(byte[])

Initializes the password.

Declaration
public virtual void InitPassword(byte[] passwordBuffer)
Parameters
Type Name Description
byte[] passwordBuffer

The initial password.

InitPassword(string)

Initializes the password.

Declaration
public virtual void InitPassword(string password)
Parameters
Type Name Description
string password

The initial password.

Initialize(SDFDoc, Obj, int)

Declaration
public override void Initialize(SDFDoc doc, Obj encrypt_dict, int custom_data)
Parameters
Type Name Description
SDFDoc doc
Obj encrypt_dict
int custom_data
Overrides
SecurityHandler.Initialize(SDFDoc, Obj, int)

IsAES()

Checks if AES encryption algorithm is used

Declaration
public bool IsAES()
Returns
Type Description
bool

true, if AES is used, false otherwise

IsAES(Obj)

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

Declaration
public bool IsAES(Obj stream)
Parameters
Type Name Description
Obj stream

A pointer to an SDF::Stream object

Returns
Type Description
bool

true if the given stream is encrypted using AES encryption.

IsMasterPasswordRequired()

Checks if master password required

Declaration
public virtual bool IsMasterPasswordRequired()
Returns
Type Description
bool

true if master password is required, false otherwise

IsModified()

Checks if security handler is modified

Declaration
public override bool IsModified()
Returns
Type Description
bool

true if security handler is modified, false otherwise

Overrides
SecurityHandler.IsModified()

IsRC4()

Checks if RC4 encryption algorithm is used

Declaration
public bool IsRC4()
Returns
Type Description
bool

true, if RC4 is used, false otherwise

IsUserPasswordRequired()

Checks if user password required

Declaration
public virtual bool IsUserPasswordRequired()
Returns
Type Description
bool

true if user password required, false otherwise

SetEncryptMetadata(bool)

Sets whether to encrypt metadata

Declaration
public void SetEncryptMetadata(bool encrypt_metadata)
Parameters
Type Name Description
bool encrypt_metadata

whether to encrypt metadata

SetModified()

Sets if security handler is modified

Declaration
public override void SetModified()
Overrides
SecurityHandler.SetModified()

SetModified(bool)

Sets if security handler is modified

Declaration
public override void SetModified(bool is_modified)
Parameters
Type Name Description
bool is_modified

true if the security handler is modified

Overrides
SecurityHandler.SetModified(bool)

SetPermission(Permission, bool)

Set the permission setting of the StdSecurityHandler.

Declaration
public virtual void SetPermission(SecurityHandler.Permission perm, bool value)
Parameters
Type Name Description
SecurityHandler.Permission 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.
bool value

true if the permission/s should be granted, false otherwise.

Implements

IDisposable
In This Article
Back to top Generated by DocFX