PdfSigner Class

Signs documents (ISO 32000-2, 12.8): a signature field whose signature is a CAdES detached signature of the file (PAdES baseline B-B, ETSI EN 319 142-1), stamped by a time stamp authority for B-T, the validation data of B-LT and the document time stamps of B-LTA.

public static class PdfSigner

Remarks

Each operation appends an incremental update to the file, so that the signatures the document already has stay valid. A document that was not read from a file is saved in full first. The changes made to a document read from a file are saved in the update.

Methods

NameDescription
AddValidationData(PdfDocument, PdfValidationData)Adds validation data to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT): the certificates and the revocation evidence of the data, and the certificates the signatures and their time stamps embed.
AddValidationData(PdfDocument, PdfValidationDataOptions)Adds the validation data of the signatures and of the document time stamps to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT), from the data of the options and of the store, without downloading anything.
AddValidationDataAsync(PdfDocument, PdfValidationDataOptions, CancellationToken)Adds the validation data of the signatures and of the document time stamps to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT): the chains of the signers and of the time stamp authorities, completed with the certificates of the options and of the store, and the revocation evidence of each certificate of the chains that is not self-issued. With PdfValidationDataOptions.DownloadMissingData, the issuers and the revocation evidence that are missing are downloaded.
Sign(PdfDocument, PdfSignatureOptions)Signs a document without time stamp (PAdES B-B).
SignAsync(PdfDocument, PdfSignatureOptions, CancellationToken)Signs a document, with the time stamp of PdfSignatureOptions.TimestampAuthority when it is set (PAdES B-T).
TimestampAsync(PdfDocument, PdfTimestampOptions, CancellationToken)Adds a document time stamp (ISO 32000-2, 12.8.5): an RFC 3161 time stamp of the file, in a signature field. After PdfSigner.AddValidationData, it protects the validation data of the signatures (PAdES B-LTA).

AddValidationData overloads

AddValidationData(PdfDocument, PdfValidationData)

PdfSigner.cs

Adds validation data to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT): the certificates and the revocation evidence of the data, and the certificates the signatures and their time stamps embed.

public static byte[] AddValidationData(PdfDocument document, PdfValidationData validationData)
Parameters
document PdfDocument
The document.
validationData PdfValidationData
The certificates and the revocation evidence; the data the store already has is not added again.
Returns

byte[] The file with the validation data.

AddValidationData(PdfDocument, PdfValidationDataOptions)

PdfSigner.cs

Adds the validation data of the signatures and of the document time stamps to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT), from the data of the options and of the store, without downloading anything.

public static byte[] AddValidationData(PdfDocument document, PdfValidationDataOptions options)
Parameters
document PdfDocument
The document.
options PdfValidationDataOptions
The options.
Returns

byte[] The file with the validation data.

Exceptions
ArgumentException
The options ask to download the missing data: use PdfSigner.AddValidationDataAsync.

AddValidationDataAsync(PdfDocument, PdfValidationDataOptions, CancellationToken)

PdfSigner.cs

Adds the validation data of the signatures and of the document time stamps to the document security store (ISO 32000-2, 12.8.4.3; PAdES B-LT): the chains of the signers and of the time stamp authorities, completed with the certificates of the options and of the store, and the revocation evidence of each certificate of the chains that is not self-issued. With PdfValidationDataOptions.DownloadMissingData, the issuers and the revocation evidence that are missing are downloaded.

net10.0

public static Task<byte[]> AddValidationDataAsync(PdfDocument document, PdfValidationDataOptions options, CancellationToken cancellationToken = default)

net11.0

public static Task<byte[]> AddValidationDataAsync(PdfDocument document, PdfValidationDataOptions options, CancellationToken cancellationToken = default)

Parameters

document PdfDocument
The document.
options PdfValidationDataOptions
The options.
cancellationToken CancellationToken
The token to monitor for cancellation requests.

Returns

Task<byte[]> The file with the validation data.

Exceptions

HttpRequestException
The revocation evidence of a certificate could not be downloaded from any of its addresses.

Sign(PdfDocument, PdfSignatureOptions)

PdfSigner.cs

Signs a document without time stamp (PAdES B-B).

public static byte[] Sign(PdfDocument document, PdfSignatureOptions options)

Parameters

document PdfDocument
The document.
options PdfSignatureOptions
The options.

Returns

byte[] The signed file.

Exceptions

ArgumentException
The certificate has no private key, the field name is used, or the options ask for a time stamp: use PdfSigner.SignAsync.
InvalidOperationException
The document has no pages, or its certification does not allow another signature.

SignAsync(PdfDocument, PdfSignatureOptions, CancellationToken)

PdfSigner.cs

Signs a document, with the time stamp of PdfSignatureOptions.TimestampAuthority when it is set (PAdES B-T).

net10.0

public static Task<byte[]> SignAsync(PdfDocument document, PdfSignatureOptions options, CancellationToken cancellationToken = default)

net11.0

public static Task<byte[]> SignAsync(PdfDocument document, PdfSignatureOptions options, CancellationToken cancellationToken = default)

Parameters

document PdfDocument
The document.
options PdfSignatureOptions
The options.
cancellationToken CancellationToken
The token to monitor for cancellation requests.

Returns

Task<byte[]> The signed file.

Exceptions

ArgumentException
The certificate has no private key, or the field name is used by a field that is not an unsigned signature field.
InvalidOperationException
The document has no pages, its certification does not allow another signature (PdfCertificationLevel.NoChanges), or a certification signature is requested and the document is already signed.
HttpRequestException
The time stamp authority could not be reached.
CryptographicException
The signature or the time stamp could not be computed.

TimestampAsync(PdfDocument, PdfTimestampOptions, CancellationToken)

PdfSigner.cs

Adds a document time stamp (ISO 32000-2, 12.8.5): an RFC 3161 time stamp of the file, in a signature field. After PdfSigner.AddValidationData, it protects the validation data of the signatures (PAdES B-LTA).

net10.0

public static Task<byte[]> TimestampAsync(PdfDocument document, PdfTimestampOptions options, CancellationToken cancellationToken = default)

net11.0

public static Task<byte[]> TimestampAsync(PdfDocument document, PdfTimestampOptions options, CancellationToken cancellationToken = default)

Parameters

document PdfDocument
The document.
options PdfTimestampOptions
The options.
cancellationToken CancellationToken
The token to monitor for cancellation requests.

Returns

Task<byte[]> The time-stamped file.

Exceptions

ArgumentException
The field name is used by a field that is not an unsigned signature field, or the digest algorithm is not supported.
InvalidOperationException
The document has no pages, or the reserved size is too small for the time stamp token.
HttpRequestException
The time stamp authority could not be reached.
CryptographicException
The response of the time stamp authority is not valid.