Security

Add security to a document using one of four encryption algorithms (listed below). All four encryption algorithms are contained in the ceTe.DynamicPDF.Cryptography namespace. Adding security to a PDF involves the following steps,

Encryption Algorithms

The following table lists the four encryption algorithms.

Encryption Algorithm Class Compatibility
40-bit RC4 Encryption RC440Security PDF 1.1 (Acrobat 3 or later)
128-bit RC4 Encryption RC4128Security PDF 1.4 (Acrobat 5 or later) *
128-bit AES Encryption Aes128Security PDF 1.5 (Acrobat 7 or later)
256-bit AES Encryption Aes256Security (FIPS Compliant) PDF 1.5 (Acrobat 10 or later)

PDF 1.5 (Acrobat 6 or later) if the UseCryptFilter is set to True (it is false by default).

Security

The Security class is the parent of Aes128Security, Aes256Security, RC440Security, and RC4128Security classes. This class has the following abstract method for encrypting a document that is implemented by its child classes.

public abstract Encrypter GetEncrypter(Byte[] id)

It returns an Encrypter instance, which is the class used for the document encryption.

Properties

Property Description
AllowCopy Gets or sets if text and images can be copied to the clipboard by the user.
AllowEdit Gets or sets if the document can be edited by the user.
AllowPrint Gets or sets if the document can be printed by the user.
AllowUpdateAnnotsAndFields Gets or sets if annotations and form fields can be added, edited and modified by the user.
OwnerPassword Gets or sets the owner password.
UserPassword Gets or sets the user password.

Inherited properties are not repeated for child classes below.

Aes128Security

The Aes128Security class represents AES 128 bit PDF document security. This class's implementation of the GetEncrypter method returns a 128 bit Encrypter.

Properties

Property Description
AllowAccessibility Gets or sets if accessibility programs should be able to read the documents text and images for the user.
AllowDocumentAssembly Gets or sets if the document can be assembled and manipulated by the user.
AllowFormFilling Gets or sets if form filling should be allowed by the user.
AllowHighResolutionPrinting Gets or sets if the document can be printed at a high resolution by the user.
DocumentComponents Gets or sets the documents components to be encrypted.

Refer to the Aes128Security API documentation for an example.

Aes256Security

The Aes256Security class represents AES 256 bit PDF document security. This class's implementation of the GetEncrypter method returns a 256 bit Encrypter. It has the same properties as the AES128Security class.

Refer to the Aes256Security API documentation for an example.

AES Encryption Document Components

AES encryption allows encrypting portions of a document. The DocumentComponents property (Aes128SecurityDocumentComponents, Aes256Security.DocumentComponents) gets or sets a document's components that are encrypted. AES encryption can apply to the following document portions using the EncryptDocumentComponents enumeration.

Document Portion Description
Entire Document (EncryptDocumentComponents.All) Encrypts the document, its metadata and any file attachments.
Entire Document except the Metadata (EncryptDocumentComponents.AllExceptMetadata) Encrypts the document, its metadata and any file attachments.
Only the Document’s file attachments (EncryptDocumentComponents.OnlyFileAttachments) Encrypts only the document’s file attachments. None of the actual PDF document or metadata are encrypted. It is important to note here that setting this EncryptDocumentComponents to OnlyFileAttachments will take precedence over any user permissions and cause them to be ignored.

Refer to Aes128Security.DocumentComponents or Aes256Security.DocumentComponents API documentation for complete examples.

RC4128Security

The RC4128Security class represents 128 bit PDF document security. This class's implementation of the GetEncrypter method returns a 256 bit Encrypter.

Properties

Property Description
AllowAccessibility Gets or sets if accessibility programs should be able to read the documents text and images for the user.
AllowDocumentAssembly Gets or sets if the document can be assembled and manipulated by the user.
AllowFormFilling Gets or sets if form filling should be allowed by the user.
AllowHighResolutionPrinting Gets or sets if the document can be printed at a high resolution by the user.
EncryptMetadata Gets or sets if the document metadata to be encrypted. Valid only when UseCryptFilter property is true.
UseCryptFilter Gets or sets if the encryption should be done with crypt filters.

Refer to the RC4128Security API documentation for a complete example.

RC440Security

The RC440Security class represents RC4 40 bit PDF document security. This class's implementation of the GetEncrypter method returns a 40 bit Encrypter. This class has no properties other than those inherited from the Security class.

Refer to the RC440Security API documentation for a complete example.

Document Passwords

When applying security to a PDF using one of the provided algorithms, an owner and/or password can be specified. When a user password is specified, the PDF viewer requires the user to complete the password prior to opening the PDF document. Leaving the user password blank (by specifying an empty string) does not require a password to open the PDF document. Whether a user password is defined or blank (empty string) the access permissions set on the document are applied. When an owner password is specified, the PDF viewer requires the user to enter the owner password when modifying the PDF.

Security Options

The RC4 40-bit encryption supports four security options:

The RC4 128-bit encryption supports the four security options above along with the following:

AES 128-bit and AES 256-bit encryption supports the 9 security options above along with the following:

Example

The following example illustrates securing a Document using RC4 128-bit encryption, not allowing content copying, and not encrypting the PDF's metadata.

RC4128Security security = new RC4128Security( "owner", "user" );
Security.UseCryptFilter = true;
security.EncryptMetadata = false;
document.Security = security;        
Dim MySecurity As RC4128Security = New RC4128Security( "owner", "user" )
MySecurity.UseCryptFilter = True
MySecurity.EncryptMetadata = False
MyDocument.Security = MySecurity 

In this topic