Skip to main content
All docs
V23.2

TsaClient Class

Allows you to generate timestamps.

Namespace: DevExpress.Office.Tsp

Assembly: DevExpress.Pdf.v23.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

Declaration

public class TsaClient :
    ITsaClient

Remarks

The TsaClient class is the default ITsaClient implementation. Use this class to generate timestamps.

Pass the URI of a timestamp server to the TsaClient constructor. You can specify the username and a password to log into the server. If the server rejects the timestamp request, a TspValidationException is thrown.

Use one of the HashAlgorithmType enumeration values to specify the timestamp’s hashing algorithm. Create the IDigestCalculator implementation and pass the newly created object to the TsaClient constructor to provide the digest value calculator to the timestamp.

Add a Timestamp to the PKCS#7 Signature

The code sample below creates a PKCS#7 signature with a timestamp. The FreeTSA server is used for demonstration purposes as a free trusted TSA client. You may wish to use another client as required.

using DevExpress.Pdf;
using DevExpress.Office.DigitalSignatures;
using DevExpress.Office.Tsp;

using (var signer = new PdfDocumentSigner("Document.pdf"))
{
    // Create a timestamp:
    ITsaClient tsaClient = new TsaClient(new Uri(@"https://freetsa.org/tsr"), 
        HashAlgorithmType.SHA256);

    // Create a PKCS#7 signature:
    Pkcs7Signer pkcs7Signature = new Pkcs7Signer("Signing Documents/certificate.pfx", "123", 
        HashAlgorithmType.SHA256, tsaClient, null, null, PdfSignatureProfile.PAdES_BES);

    // Apply the signature to an existing form field:
    var santuzzaSignature = new PdfSignatureBuilder(pkcs7Signature, "Sign");

    // Specify an image and signer information:
    santuzzaSignature.SetImageData(System.IO.File.ReadAllBytes("Signing Documents/SantuzzaValentina.jpg"));
    santuzzaSignature.Location = "Australia";
    santuzzaSignature.Name = "Santuzza Valentina";
    santuzzaSignature.Reason = "I Agree";

    // Sign and save the document:
    signer.SaveDocument("SignedDocument.pdf", santuzzaSignature);
}

Create a Document-Level Timestamp

The code sample below creates a document-level timestamp and applies it to a signature form field. The FreeTSA server is used for demonstration purposes as a free trusted TSA client. You may wish to use another client as required.

using DevExpress.Pdf;
using DevExpress.Office.DigitalSignatures;
using DevExpress.Office.Tsp;

using (var signer = new PdfDocumentSigner("Document.pdf"))
{
    // Create a timestamp:
    ITsaClient tsaClient = new TsaClient(new Uri(@"https://freetsa.org/tsr"), HashAlgorithmType.SHA256);

    // Create a new signature form field:
    var signatureFieldInfo1 = new PdfSignatureFieldInfo(1);
    signatureFieldInfo1.Name = "SignatureField1";
    signatureFieldInfo1.SignatureBounds = new PdfRectangle(200, 200, 250, 250);

    // Create a document-level timestamp:
    PdfTimeStamp pdfTimeStamp = new PdfTimeStamp(tsaClient);

    // Apply this timestamp to the form field:
    var timeStampSignature = new PdfSignatureBuilder(pdfTimeStamp, signatureFieldInfo1);

    // Sign and save the document:
    signer.SaveDocument("SignedDocument.pdf", timeStampSignature);
}

Implements

Inheritance

Object
TsaClient
See Also