Skip to main content

Security

Version: 12.0

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,

  • selecting an encryption algorithm to use,
  • setting user and/or owner passwords, and
  • specifying user access permissions.

Encryption Algorithms​

The following table lists the four encryption algorithms.

Encryption AlgorithmClassCompatibility
40-bit RC4 EncryptionRC440SecurityPDF 1.1 (Acrobat 3 or later)
128-bit RC4 EncryptionRC4128SecurityPDF 1.4 (Acrobat 5 or later) *
128-bit AES EncryptionAes128SecurityPDF 1.5 (Acrobat 7 or later)
256-bit AES EncryptionAes256Security (FIPS Compliant)PDF 1.5 (Acrobat 10 or later)
important

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​

PropertyDescription
AllowCopyGets or sets if text and images can be copied to the clipboard by the user.
AllowEditGets or sets if the document can be edited by the user.
AllowPrintGets or sets if the document can be printed by the user.
AllowUpdateAnnotsAndFieldsGets or sets if annotations and form fields can be added, edited and modified by the user.
OwnerPasswordGets or sets the owner password.
UserPasswordGets or sets the user password.
info

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​

PropertyDescription
AllowAccessibilityGets or sets if accessibility programs should be able to read the documents text and images for the user.
AllowDocumentAssemblyGets or sets if the document can be assembled and manipulated by the user.
AllowFormFillingGets or sets if form filling should be allowed by the user.
AllowHighResolutionPrintingGets or sets if the document can be printed at a high resolution by the user.
DocumentComponentsGets or sets the documents components to be encrypted.
info

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.

info

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 PortionDescription
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.
info

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​

PropertyDescription
AllowAccessibilityGets or sets if accessibility programs should be able to read the documents text and images for the user.
AllowDocumentAssemblyGets or sets if the document can be assembled and manipulated by the user.
AllowFormFillingGets or sets if form filling should be allowed by the user.
AllowHighResolutionPrintingGets or sets if the document can be printed at a high resolution by the user.
EncryptMetadataGets or sets if the document metadata to be encrypted. Valid only when UseCryptFilter property is true.
UseCryptFilterGets or sets if the encryption should be done with crypt filters.
info

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.

info

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:

  • Restrict document printing

  • Restrict document Modification

  • Restrict copying text or graphics from the document

  • Restrict updating or adding text annotations or form fields

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

  • Restrict fill in existing form fields

  • Restrict extract text and graphics for accessibility programs

  • Restrict document assembly

  • Restrict high Resolution Printing

  • Encrypt all document contents except Metadata (Acrobat 6 and later compatible)

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

  • Encrypting only file attachments

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

[EncryptPDF.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/EncryptPDF.cs){#gitlink-id target=_blank}


[EncryptPDF.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/EncryptPDF.vb){#gitlink-id target=_blank}