PdfEncryption Class

The encryption of a document: by the standard security handler (ISO 32000-2, 7.6.4), with passwords, or by the public-key security handler (7.6.5), for the certificates of recipients. Set PdfDocument.Encryption to encrypt a document when it is saved.

public sealed class PdfEncryption

Remarks

The user password opens the document with the permissions; the owner password opens it with every permission. An empty user password opens the document without a prompt: the permissions are then the only protection, which the readers enforce. A recipient opens the document with the private key of its certificate, with its permissions. A document that is read from an encrypted file keeps its encryption: its PdfDocument.Encryption has no passwords and no recipients, and the document is saved with the keys of the file.

Constructors

NameDescription
PdfEncryption(IEnumerable<PdfEncryptionRecipient>)Initializes a new instance of the PdfEncryption class that encrypts a document for the certificates of recipients (the public-key security handler, adbe.pkcs7.s5): each opens the document with its private key.
PdfEncryption(string, string)Initializes a new instance of the PdfEncryption class that encrypts a document with passwords.

PdfEncryption overloads

PdfEncryption(IEnumerable<PdfEncryptionRecipient>)

PdfEncryption.cs

Initializes a new instance of the PdfEncryption class that encrypts a document for the certificates of recipients (the public-key security handler, adbe.pkcs7.s5): each opens the document with its private key.

public PdfEncryption(params IEnumerable<PdfEncryptionRecipient> recipients)
Parameters
recipients IEnumerable<PdfEncryptionRecipient>
The recipients; at least one.
Exceptions
ArgumentException
There is no recipient, or a recipient is null.

PdfEncryption(string, string)

PdfEncryption.cs

Initializes a new instance of the PdfEncryption class that encrypts a document with passwords.

public PdfEncryption(string userPassword, string ownerPassword)
Parameters
userPassword string
The user password; empty to open the document without a password.
ownerPassword string
The owner password; empty for the user password.

Properties

NameDescription
AlgorithmGets the algorithm. The default is PdfEncryptionAlgorithm.AesWith256BitKey, which needs PDF 2.0: the version of the file is raised to what the algorithm needs.
EncryptMetadataGets a value indicating whether the XMP metadata stream is encrypted. The default is true. The RC4 algorithms of the standard security handler always encrypt it.
OwnerPasswordGets the owner password, or null for the encryption of a document read from a file or encrypted for certificates.
PermissionsGets the operations the user password allows, or the recipients whose PdfEncryptionRecipient.Permissions is null. The default is PdfPermissions.All.
RecipientsGets the recipients the document is encrypted for: empty for passwords, and for the encryption of a document read from a file.
UserPasswordGets the user password, or null for the encryption of a document read from a file or encrypted for certificates.
UsesCertificatesGets a value indicating whether the document is encrypted for certificates (the public-key security handler) instead of passwords.

Gets the algorithm. The default is PdfEncryptionAlgorithm.AesWith256BitKey, which needs PDF 2.0: the version of the file is raised to what the algorithm needs.

public PdfEncryptionAlgorithm Algorithm { get; init; }

EncryptMetadata

PdfEncryption.cs

Gets a value indicating whether the XMP metadata stream is encrypted. The default is true. The RC4 algorithms of the standard security handler always encrypt it.

public bool EncryptMetadata { get; init; }

Property value

bool

OwnerPassword

PdfEncryption.cs

Gets the owner password, or null for the encryption of a document read from a file or encrypted for certificates.

public string? OwnerPassword { get; }

Property value

string?

Permissions

PdfEncryption.cs

Gets the operations the user password allows, or the recipients whose PdfEncryptionRecipient.Permissions is null. The default is PdfPermissions.All.

public PdfPermissions Permissions { get; init; }

Property value

PdfPermissions

Gets the recipients the document is encrypted for: empty for passwords, and for the encryption of a document read from a file.

public IReadOnlyList<PdfEncryptionRecipient> Recipients { get; }

UserPassword

PdfEncryption.cs

Gets the user password, or null for the encryption of a document read from a file or encrypted for certificates.

public string? UserPassword { get; }

Property value

string?

UsesCertificates

PdfEncryption.cs

Gets a value indicating whether the document is encrypted for certificates (the public-key security handler) instead of passwords.

public bool UsesCertificates { get; }

Property value

bool