Skip to content

2.23 Encryption Support

OgreTransporter edited this page Mar 2, 2020 · 1 revision

The PDF File Writer library provides support to AES 128 and Standard 128 (RC4) encryption. For more information please refer to PDF Reference sixth edition (Version 1.7) section 3.5 Encryption. The PDF File writer supports two types of encryption filters, the AES-128 and Standard 128. The Standard 128 is RC4 encryption. It is considered unsafe. For new project do not use it. It does not support public key security to encode recipient list.

To encrypt your PDF document call one of four SetEncryption methods defined in PdfDocument class:

Set Encryption with no Arguments

The PDF File Writer library will encrypt the PDF document using AES-128 encryption. The PDF reader will open the document without requesting a password. Permissions flags are set to allow all.

Document.SetEncryption();

Set Encryption with one argument

The PDF File Writer library will encrypt the PDF document using AES-128 encryption. The argument is permissions. Permission flags are defined below. You can or together more than one permission. The PDF reference manual has full description of permissions. The PDF reader will open the document without requesting a password.

Document.SetEncryption(Permission Permissions);

Set Encryption with two Arguments

The PDF File Writer library will encrypt the PDF document using AES-128 encryption. The two arguments are user password and permissions. The PDF reader will open the document with user password. Permissions will be set as per argument.

Document.SetEncryption(String UserPassword, Permission Permissions);

Set Encryption with four Arguments

The PDF File Writer library will encrypt the PDF document using either EncryptionType.Aes128 encryption or EncryptionType.Standard128 encryption. The four arguments are user password, owner password, permissions and encryption type. If user password is null, the default password will be taken. If owner password in null, the software will generate random number password. The Standard128 encryption is considered unsafe. It should not be used for new projects. A PDF reader such as Acrobat will accept either user or owner password. If owner password is used to open document, the PDF reader will open it with all permissions set to allow operation.

Document.SetEncryption(String UserPassword, String OwnerPassword, Permission Permissions, EncryptionType Type);

Permission flags are as follows:

// Full description is given in
// PDF Reference Version 1.7 Table 3.20
public enum Permission
	{
	None = 0,
	LowQalityPrint = 4,	// bit 3
	ModifyContents = 8,	// bit 4
	ExtractContents = 0x10,	// bit 5
	Annotation = 0x20,	// bit 6
	Interactive = 0x100,	// bit 9
	Accessibility = 0x200,	// bit 10
	AssembleDoc = 0x400,	// bit 11
	Print = 0x804,		// bit 12 + bit 3
	All = 0xf3c,		// bits 3, 4, 5, 6, 9, 10, 11, 12
	}
Clone this wiki locally