Class StdSecurityHandler
Standard Security Handler is a built-in password-based security handler.
Implements
Inherited Members
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):
|
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
Remarks
This callback must not obtain the authorization data
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
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
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
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
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
GetEncryptionAlgorithmID()
Gets encryption algorithm
Declaration
public override int GetEncryptionAlgorithmID()
Returns
| Type | Description |
|---|---|
| int | encryption algorithm |
Overrides
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
GetKeyLength()
Gets key length
Declaration
public override int GetKeyLength()
Returns
| Type | Description |
|---|---|
| int | length of the encryption key |
Overrides
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 |
Overrides
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
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 |
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
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
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
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:
|
| bool | value | true if the permission/s should be granted, false otherwise. |